Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

6.13 Swapping Sections, Alternating Background Color

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 different. 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.

Example 6-5. Alternating the background color.

A common reason for alternating the background color of sections is to make the report easier to read. It can be hard to visually move your eyes across a report and stay on the same row. To make this easier to do, reports often alternate the background color of each row. This is similar to the green-bar report paper that was frequently used at corporations.

This is done by creating two detail sections with different background colors. Using Basic syntax, the Suppress formatting formula for each section would be either

Formula = Remainder(RecordNumber, 2) = 0

Or

Formula = Remainder(RecordNumber, 2) = 1

Once you become familiar with all the different formatting options available within Crystal Reports, you will find that there are many ways to do the same thing. For example, if you want to change the background color of a section to red when a salesperson’s quota isn’t met, there are two ways you could do it. One solution would be to have two different sections as just discussed. Another solution would be to use only one section and put that same formula in the Background Color property. This will only turn the background color to red when the formula is true. Both solutions work equally well, although in this example, using a single section would require less work. The more you work with Crystal Reports, the more you will learn different tricks. The ones you use will depend upon what you think best fits the situation at the time.