Sunday, January 30, 2011

Crystal Reports : Conditionally changing font color

You can specify the color of any font in your report to change based upon a "condition".
A typical example would include making a sales total field "red" if it drops below a certain value.
Let's assume our Sales Total field is called "SalesTotal".
Step #1 : Right-click on the field in question and select Format Field.
Step #2 : Click on the "Font" tab.
Step #3 : Click on the "x-2" (formula) button next to Color.
Step #4 : Use the following fomula: if SalesTotal < 100 then crMaroon else crBlack

This formula forces the sales total to be drawn in red if it drops below 100, oherwise it stays black.

Pro Tip: When testing a condition to change the font, any fields on the report are available to use.

No comments: