Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

8.03 Returning a Value, Referencing Fields

Returning a Value

Formulas are always used to return a value. The data types of these return values can be Number, Currency, String, Boolean, Date, Time and DateTime. You cannot return data types of range and array.

Formulas return values by assigning the value to the Formula variable. Formulas have to always return a value. The following code simply returns the value True.

Formula = True

If a formula has multiple statements that return a value, all the assignments must be of the same data type. Although there is no way to specifically state what that data type is, the compiler will compare all the assignments and check them for consistency.

‘The following IS NOT VALID due to the different data types returned
If Age > 65 Then
Formula = "Retired"
Else
Formula = Age
End If

To return a value with Crystal syntax, put the value on a line by itself. Nothing else should appear on the line. The following code True if the employee received a bonus. If not then False is returned.

If {Employee.Bonus} > 0 Then
True
Else
False

Referencing Report Fields

Writing formulas requires referencing all types of data from your report and the databases that the report uses. The types of data that can be referenced consist of running total fields, the results of other formulas, and table fields. The syntax for referencing fields in a formula is to surround the field name with curly brackets. The syntax for referencing the field name is dependent upon the type of field it is.

Formulas are referenced by putting @ in front of the name.

{@Formula}

Parameters are referenced with a ? in front of the name.

{?Parameter}

Running total fields are referenced by putting # in front of the name.

{#RunningTotal}

Table fields are referenced by separating the table name and the field name with a period between the two. Spaces are allowed.

{Customer.First Name}

Group fields use the field name with the GroupName() formula.

GroupName({Table.GroupField})

Summary fields pass the field name and the group field to the summary function.

Sum({Table.FieldName}, {Table.GroupName})