Chapter 4 - Selecting Records with Parameters


This chapter first shows you how to filter data using the Select Expert and then shows you how to create advance filters using parameters. Parameters are covered in great detail because they are also used within report formulas and for custom formatting. The effective use of parameters within record selection formulas and custom formatting lets you create dynamic reports that are tailored to each specific user.

Become a Crystal Reports expert with the authoritative resource available. The tuturials and tips in this book will take your skills to the next level.
Buy at

This is an excerpt from the book Crystal Reports Encyclopedia. Click to read more chapter excerpts.

Advanced Tutorials

Tutorial 4-5. Creating DCPs

The previous tutorials in this chapter have focused on different ways to modify the Group.rpt sample report and customize it with parameters. Well, this last tutorial is no different. It builds on the other tutorials by showing you how to use DCPs to create the same parameters and demonstrates how it makes them more user friendly.

The previous tutorials created a parameter for the fields Country and Customer Id. They used the database tables to build a static list of values that the user chose from. The downside to doing it this way is that the list of customers to pick from was quite large. Even though the user could only choose to print the customers from either the USA or Canada, they still had to scroll through every customer in the database even if that customer was located in a different country.

We're going to modify the report requirements to illustrate the usage of DCPs. The report will now let the user print the report for one or more customers and the user will narrow down the list of customers to pick from by first picking the Country. Once they pick the Country then only the customers located in that country will be displayed.

  1. Open the Crystal Reports sample report Group.rpt. Save it as Tutorial DCPs.rpt.
  2. Right-click on the Parameter Fields list and select New.
  3. Enter the parameter name Customers to print.
  4. Select the Dynamic option.
  5. For the Prompt Group Text type in Select the customers to print.
  6. Click on the Insert button and select the Country field. Leave the Description and Parameters column alone because they aren't needed.
  7. We want to let the user enter customers from more than one country. In the Options, set the option Allow Multiple Values to True.
  8. For the second field select Customer Id and for the description field select Customer Name. Click on the Parameters column so that a parameter is created for this field.
  9. We want to let the user print multiple customers as well. In the Options box, set the option Allow Multiple Values to True.
  10. At this point two prompts have been created and the final prompt saves the Customer Id field to the parameter. Click the OK button to save the parameter.
  11. Now we want to set the record selection formula so that it filters on the Customer Id parameter. Select the menu items Report | Select Expert.
  12. When the Choose Field dialog box opens, select the Customer.Customer Id field and click the OK button.
  13. For the selection critieria choose Is Equal To.
  14. For the field to match to, choose the parameter {?Customers – Customer Id}.
  15. Click the OK button to save your changes. The Enter Values parameter will automatically open. It should look similar to the following figure.

  16. The first prompt lets you select multiple countries. As you choose each country the Customer list changes to reflect which customers are in that Country. Choose as many customers as you wish to print and click the OK button. You report is updated to reflect the customers you picked.


To read all my books online, click here for the Crystal Reports ebooks.