Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

5.12 Using Conditional Formatting

Using Conditional Formatting

Reports by their very nature are static. Although the printed data changes and the calculation results are different every time, the report format stays the same. For example, if the first field in a column has a font of Arial and is black, every field in that column is also going to have a font of Arial and be black. After all, if the fields in a column each had a different font, it would be very hard to read and people would question the abilities of the report designer. But wouldn’t it be nice to use visual cues to highlight important data? For example, you could change the color of an inventory quantity to red when it is below the minimum level. The reader immediately knows that the item needs to be reordered. There might even be a special note to the side of the report stating whom to notify. In this circumstance, making a report dynamic increases its usefulness to the reader without adding clutter.

Crystal Reports gives you the ability to write formulas that dynamically modify the properties and behavior of fields and sections on a report. This is done by attaching a conditional formatting formula with an object’s property. For example, you can show or hide a section by using a formula that returns either True or False in the Suppress property. You could also use a formula that returns a special message at the bottom of each page.

Modifying the formatting of a report object is done by right-clicking on it and selecting Format Field from the pop-up menu. This opens the Format Editor dialog box which lets you modify each property. Next to each property is a Formula button. It looks like a horizontal pencil with a blue “X-2” above it.



Figure 5-9. The Formula button.

Clicking on this button opens the Formula Workshop dialog box. Just like we discussed earlier, type your formula in the Definition area. Click the Save and Close button when you are finished.

After saving the formula, you are returned to the Format Editor dialog box to make more changes. You’ll notice that the Formula button looks different now. Since it has a conditional formula associated with it, it has red letters and the pencil is at a 45 degree angle.



Figure 5-10. Conditional formatting has been applied.

This new button makes it easy to look at the Format Editor dialog box and immediately know which properties have conditional formatting associated with them. This is important when you are trying to fix formatting problems because conditional formatting often overrides the default property value and you need to know when something is going on behind the scenes.