To add the custom function to a Crystal report
This procedure works only with a project that has been created from Project Setup. Project Setup contains specific namespace references and code configuration that is required for this procedure, and you will be unable to complete the procedure without that configuration. Therefore, before you begin this procedure, you must first follow the steps in Project Setup.
In this section, you create a Crystal report that accesses your custom function.
- In Solution Explorer, right-click the project name in bold type, point to Add, and then click Add New Item.
- In the Add New Item dialog box, in the Templates view, select the template named Crystal Report.
- In the
Name field, enter the name
FunctionTest.rpt, and then click
If you have not registered before, you are asked to register. To learn how to register, see Crystal Reports Product Keycode and Registration Number.
- In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard.
- In the Choose an Expert panel, select Standard, and then click OK.
- In the Available Data Sources panel of the Standard Report Creation Wizard window, expand the Create New Connection folder.
- From the subfolder that opens, expand the ODBC (RDO) folder.
the ODBC (RDO) window, select the correct ODBC DSN entry for your version of Crystal Reports, as
Entry for Xtreme Sample Database, and then click
The ODBC (RDO) folder expands and shows the Xtreme Sample Database.
- Expand the Tables node and select the Customer table.
- Double-click the Customer table to move the table into the Selected Tables panel, and then click Next.
- CTRL-click Customer Name, Last Year's Sales, and City.
- Click the > symbol to move these fields into the Fields to Display panel, then click Next.
the Available Fields panel,
under Report Fields, select
Customer.City, click the
> symbol to move the field
into the Group By panel, and
then click Finish.
The FunctionTest report is created and loaded into the main window of Visual Studio.
the Field Explorer is not
visible, on the Crystal Reports toolbar, click
Toggle Field View.
Another way to display the Field Explorer is to go to the Crystal Reports menu, and then click Field Explorer.
- In the Field Explorer, right-click Formula Fields, and then click New...
the Formula Name dialog box,
type the name MyFunctionFormula,
and then click Use Editor.
The Formula Workshop window is displayed, showing four panels horizontally.
- In the third panel, expand Functions.
Expand Additional Functions, and
within it expand Visual Basic UFLs
The function that you created is displayed: ConvertUSDollarsToCDN.
The ConvertUSDollarsToCDN() function appears in the lower panel, where you can now create your formula.
- In the lower panel, place your cursor within the function brackets.
the second panel, expand Report
Fields, and then double-click Customer.Last Year's Sales.
Customer.Last Year's Sales is entered as the parameter within the ConvertUSDollarsToCDN function.
the toolbar, click Check.
The formula is verified, with no errors found.
- Close the Formula Editor.
- From the Field Explorer, within the Formula Fields node, drag MyFunctionFormula to the right of the Last Year's Sales field in the Detail section of the report.
- Arrange the fields to fit correctly on the report.
Main Report Preview.
The report is displayed, with your custom function having calculated the value of the MyFunctionFormula field.
- Click Main Report to exit Preview mode.