Crystal Reports  

Conditional Attribute Properties

A conditional attribute property tests to see which of two or more conditions is met. The program then applies the formatting appropriate to the condition. For example, assume that you want values under quota printed in red, and all other values printed in black. The program tests to see whether the value is under quota or not. If the value is under quota, then the program applies the red attribute; if the value is not under quota, then the program applies the black attribute.

Use an If-Then-Else formula for this kind of conditional formatting.

Crystal Syntax Example

If Condition A Then
   crRed
Else
   crBlack

Basic Syntax Example

If Condition A Then
   formula = crRed
Else
   formula = crBlack
End If

When conditional attribute properties are set up, Crystal Reports loads a selection of attributes into the Functions list in the Formula Editor. Double-click any of these attributes to add it to a formula. For example, if you are setting horizontal alignment conditionally, the Functions list contains attributes such as DefaultHorAligned, LeftAligned, and Justified. If you are setting borders conditionally, the Functions list contains attributes such as NoLine, SingleLine, and DashedLine.

Note   Always include the Else keyword in conditional formulas; otherwise, values that don't meet the If condition may not retain their original format. To retain the original format of values that don't meet your If condition, use the DefaultAttribute function.

Crystal Syntax Example

If Condition A Then
   crRed
Else If Condition B Then
   crBlack
Else If Condition C Then
   crGreen
Else
   crBlue

Basic Syntax Example

If Condition A Then
   formula = crRed
ElseIf Condition B Then
   formula = crBlack
ElseIf Condition C Then
   formula = crGreen
Else
   formula = crBlue
End If

See Also

Conditional Formatting Functions (Basic Syntax) | Conditional Formatting Functions (Crystal Syntax) | Inserting Formulas