Export (0) Print
Expand All

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.

  1. In Solution Explorer, right-click the project name in bold type, point to Add, and then click Add New Item.
  2. In the Add New Item dialog box, in the Templates view, select the template named Crystal Report.
  3. In the Name field, enter the name FunctionTest.rpt, and then click Add.

    If you have not registered before, you are asked to register. To learn how to register, see Crystal Reports Product Keycode and Registration Number.

  4. In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard.
  5. In the Choose an Expert panel, select Standard, and then click OK.
  6. In the Available Data Sources panel of the Standard Report Creation Wizard window, expand the Create New Connection folder.
  7. From the subfolder that opens, expand the ODBC (RDO) folder.
  8. In the ODBC (RDO) window, select the correct ODBC DSN entry for your version of Crystal Reports, as explained in ODBC DSN Entry for Xtreme Sample Database, and then click Finish.

    The ODBC (RDO) folder expands and shows the Xtreme Sample Database.

  9. Expand the Tables node and select the Customer table.
  10. Double-click the Customer table to move the table into the Selected Tables panel, and then click Next.
  11. CTRL-click Customer Name, Last Year's Sales, and City.
  12. Click the > symbol to move these fields into the Fields to Display panel, then click Next.
  13. In 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.

  14. If the Field Explorer is not visible, on the Crystal Reports toolbar, click Toggle Field View.

    Note Note

    Another way to display the Field Explorer is to go to the Crystal Reports menu, and then click Field Explorer.

  15. In the Field Explorer, right-click Formula Fields, and then click New...
  16. In the Formula Name dialog box, type the name MyFunctionFormula, and then click Use Editor.

    The Formula Workshop window is displayed, showing four panels horizontally.

  17. In the third panel, expand Functions.
  18. Expand Additional Functions, and within it expand Visual Basic UFLs (u2lcomm.dll).

    The function that you created is displayed: ConvertUSDollarsToCDN.

  19. Double-click ConvertUSDollarsToCDN.

    The ConvertUSDollarsToCDN() function appears in the lower panel, where you can now create your formula.

  20. In the lower panel, place your cursor within the function brackets.
  21. In 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.

  22. On the toolbar, click Check.

    The formula is verified, with no errors found.

  23. Close the Formula Editor.
  24. 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.
  25. Arrange the fields to fit correctly on the report.
  26. Click Main Report Preview.

    The report is displayed, with your custom function having calculated the value of the MyFunctionFormula field.

  27. Click Main Report to exit Preview mode.
Show:
© 2015 Microsoft