Crystal Reports – Displaying Parameter Values

Question: I have created several prompts in my report. How do I display what was selected?

Answer: This is a common request. Typically, parameters are used to let someone filter the records that get pulled back. Sometimes they are used in grouping or sorting. In any case, it is always nice to show what is selected on the report. I will go one step further and state that showing everything selected in a cover page is a best practice.

Parameters come in varying levels of complexity. The easiest to display is the single value prompt. Displaying a multi-value or range parameter can be a little trickier.

Single Value Parameters: These can just be dropped into the report from the Field Explorer. They will display just as any other field. You can format them as you like. It is good practice to add labels in from of the parameter fields using text boxes. You can go one step further and insert the field into the text box. I suggest making all of the formatting changes you want before moving the field into the text box. You can still format the field once it is in a text box. However, you will only be able to change text formatting like bolding and color.

Another way to display single prompt values is to incorporate them into a formula. This is the same thing as concatenation. You are just adding the field to text with an ampersand (&). You can use the ToText() function to manipulate the formatting. The problem with doing things this way is that once the formula field is placed into the report you can only make formatting changes to the whole formula. With the method above, the text inside the text box and the parameter value can be formatted independently.

Range Value Parameters: When you choose a parameter to allow a range of values, you are forced to use formulas in order to display the values. Just placing them on the report will only display the very first choice. The most typical range parameter is a date range. When working with these, you generally just want to display the lower and upper ends of the range. This can be done by using the Minimum() and Maximum() functions. But, the real power comes from using the ToText() function in conjunction with theses two functions.

Once you have the formula created, you can place it in the report. Again, if you create one long text string as your formula, you will only be able to format the whole thing once it is placed on the report. If you want to use separate formatting for the minimum and maximum values, create two formulas.

For example, to display a date range for records chosen such as “for records between 10/01/2004 and 10/31/2004” you would use two formulas and a text box:

Formula 1: ToText( Minimum( {?My Date Range Parameter}), “dd/MM/yyyy”) Formula 2: ToText( Maximum( {?My Date Range Parameter}), “dd/MM/yyyy”)

 

Multi Value Parameters: Multi-value parameters are the most difficult to display. This is because the values are stored as an array. Therefore, you need to follow the same logic you would to display all values in an array. Luckily, Crystal comes with an easy method for displaying the values of a string array, the Join() function. This built-in function lets you separate all of the values in the array. However, this only works with string parameters. If you are using any other type, you will need to loop through the values and add them to a variable – see example formula below.

Example Formula (Number-based Parameter)

Local numberVar i; Local stringVar sParameter := “”; For i := 1 To UBound({?My Parameter}) Do     //loop through the whole parameter     sParameter := sParameter & “, ” & ToText({?My Parameter}[i], “0”)  //append the current value ; Mid(sParameter, 3)  //remove the first comma and space

Tags: