Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

8.08 Tutorial 8-3 Suppressing Sections for a Repeated Field

Tutorial 8-3. Suppressing sections for a repeated field.

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 Previous() and Next(). The Previous() function compares the current record’s value to the previous record’s value. The Next() 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 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} = Previous({Orders.Customer Id}) then
True
Else
False;

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

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

Tutorial 8-4. Swapping sections with each other.

Another practical application of using multiple sections is having the same information in each section but formatting them differently. Conditional formatting lets you toggle each section so that only one section is printed at any given time and the other sections are hidden. To implement this, set each section to print using the opposite logic of the other section. For example, a company could have one client that generates a large percentage of revenue. That client asked that their invoices get formatted in a particular way. Although the data is the same as all the other invoices being printed, the format is customized for this one client.

To solve this problem, create duplicate sections for each part of the invoice. In the Suppress formatting option set the formula to only display the special sections for that customer. The other sections will have the opposite logic so that they get printed when it isn’t that customer.

Another example is when printing multi-national reports that are grouped by country. Countries have data that is unique and isn’t filled in for the other countries. People reading the report would get distracted if there were a lot of blank fields allocated for data that doesn’t apply to the current country. To fix this, create a different section for each country and only put the fields in the section that are applicable to that country.

The following code listings demonstrate displaying a section based upon the country. The first section should be shown every time the country is “USA”. The second section only gets shown when the country is “CA”.

For the first section, go to the Section Editor and click the Formula Workshop button for the Suppress section. It would have the following formula:

If {Customer.Country}=”USA” Then
False
Else
True;

In this formula, if the country is “USA” then the formula returns False so that the section is shown. Otherwise it returns True to suppress the section. For the second section, we want to use similar logic but return opposite Boolean values.

If {Customer.Country}=”CA” Then
False
Else
True;

One last example of using multiple sections is for alternating the type of chart displayed. Many formatting properties of a chart can use conditional formatting formulas, but some properties, like the type of chart (Line, Bar, etc.) can’t be changed dynamically. Instead, you can use multiple sections to display different types of charts that couldn’t be changed just by using conditional formatting. To do this, create multiple sections and put a different type of chart in each section. The charts show the same data, they just do so using a different chart type. Then use conditional formatting with the Suppress property to show the appropriate chart at the right time.