Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

6.12 Suppressing Repeated Fields

Example 6-3. Suppressing sections for repeated fields.

Individual report objects have a Suppress If Duplicated property which suppresses the object if its data is the same as the previous record. This prevents the report from duplicating the same information multiple times. But sections don’t have this property because Crystal Reports would have to analyze every field within the report section to make this decision. But you can write your own formula to do this and only base it on the fields that are important.

Crystal Reports gives you two formulas for comparing the current record to an adjacent record. In the Function Window under the Print State category, it lists the functions PreviousValue() and NextValue(). The PreviousValue() function compares the current record’s value to the previous record’s value. The NextValue() function does just the opposite by comparing it to the following record’s value. It returns True if the values match. You can use these functions to suppress an entire section if certain fields don’t change from one record to the next.

The following Basic syntax code is the conditional formatting for the Suppress property of the Details section. It tests if the Orders.CustomerId field is the same as the previous record, and if so, the section is suppressed.

If ({Orders.Customer Id} = PreviousValue (({Orders.Customer Id}) Then
Formula = True
Else
Formula = False
End If

Question: Is it possible to use a function such as NextValue (NextValue (field))? This would let me print out the value of the next two or three records.

Answer: No, you can’t nest multiple NextValue() functions inside each other. You can only get the value of one record at a time.