As Crystal Reports has become increasingly advanced over the years, the number of ways to customize reports has also increased. However, passing data to a report hasn’t changed much. Parameters are still the preferred method of passing data to a report. This chapter explores how to create parameters, query the user for input, and use parameters to customize a report. Parameters have been a very effective way to getting user input, but parameters are showing their age and are ripe for improvement now that Crystal Reports have been integrated into .NET. Formulas address some of the parameters’ weaknesses. Formulas are easier to work with during runtime and are less complex to set up. This is discussed in more detail in Chapter 16.
Inputting Parameters
Crystal Reports considers parameters to be the programming language equivalent of a constant data type. The parameter is assigned a value when the report loads and that value never changes. A parameter is like any other field on the report: It can be displayed on the report, used in filters, and used to change the formatting of report objects.
In their simplest form, parameters are used as an easy way to let the user enter a value. At another level, they can be thought of as a way of creating advanced input boxes. Parameters can have default values defined in such a way that the user is able to enter the value by selecting it from a predefined list in the combobox. The programmer controls how many options a user has in the combobox. The section on default values details the setting up of parameters in this way. When a report loads, parameters get their values by displaying a dialog box to the user. This dialog box prompts the user for information and it has input fields for the user to enter one or more values. Once the user closes the dialog box, the report uses the user input to generate the report. An example of this is a report that prints records between a valid data range. Parameters confine the beginning and ending date ranges.