Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

6.13 Non-Blank Sections, Repeated Fields

Example 6-2. Adding non-blank sections.

If you can use sections to suppress blank lines, you can do just the opposite: use sections to show special information. For example, you may want a report to only print a section for unique circumstances. There are a multitude of examples on how to use this feature. An employee report could print a special note if an employee’s birthday falls within the current month. Invoices can print reminders to late customers that they need to pay or else penalties will be incurred. A recipe listing can print additional notes for favorite recipes. Each example benefits from using multiple sections because if the section doesn’t have any data to print, additional room isn’t allocated on the report.

Example 6-3. Suppressing sections for a repeated field.

The Suppress If Duplicated format option suppresses a field if its data is duplicated, but this option isn’t available for suppressing entire records. Instead, write your own formula for this. The formula uses the PreviousValue() function to compare the current value of a field to the value in the previous record. If it returns True, the entire section is suppressed.

This code tests if the Orders.CustomerID field has been repeated. Take the following Basic syntax code and use is as the formula for the Suppress option for the section.

Formula = ({Orders.Customer Id} = PreviousValue({Orders.Customer Id}))

Example 6-4. Swapping sections with each other.

Dynamic formatting is implemented using multiple sections. They can be used so that they both have similar information, but they are formatted completely differently. Only one section is printed at any given time and the other section is hidden. Set each section to print using the opposite logic of the other. For example, a company could have a large client that gets the rules bent for them since they generate a large percentage of the revenue. This client requires their invoices to be in a certain format that simplifies their internal record keeping. Although the data is the same as all the other invoices being printed, the format is customized.

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 doesn’t need to get printed 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. Set the formula in the Suppress format property to only display the section when the data relates to that country.