Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

7.09 Evaluation Time Defaluts

Evaluation Time Defaults

Chapter 1 discussed the Two-Pass Processing Model. Knowing how this model works is especially important when writing formulas. The type of formula determines when it is processed. Where you place a formula on a report and the functionality within that formula affects when the formula is evaluated and whether it returns the expected value or not. A formula can be placed on any section of your report, but you should plan this in advance so that you can guarantee the proper results. To determine where to place a formula, you need to know the rules that Crystal Reports uses to evaluate functions. The following list is the rules that are applied.

  • A formula that only references variables (it doesn’t use group/summary fields or database fields) is evaluated before any records are read.
  • Formulas using database fields are evaluated while records are being read.
  • Formulas using group fields, summary fields, or page related fields (e.g. the page number) are evaluated after the records are read and while the report is being printed.
  • You can’t determine which formula within a section will be called first. This is because formulas within the same section are not evaluated in any particular order.

There are times when the default rules listed above will not give you the results you desire. For example, there may be a situation where you have two formulas in the same section and one formula relies upon the other to be called first. According to the default rules listed above, you know that there is no way to determine which one will be called first. You need some way to force one formula to be called before the other. Fortunately, Crystal Reports lets you override the default rules to fit your particular situation. There are four keywords that let you set when a formula will be evaluated: BeforePrintingRecords, WhileReadingRecords, WhilePrintingRecords, and EvaluateAfter. The keyword is added to the beginning of a formula to set when it gets evaluated. These keywords are listed in Table 7-1.

Table 7-1. Evaluation Time Keywords

Evaluation Time Keyword Description
BeforeReadingRecords Evaluate the formula before any database records are read.
WhileReadingRecords Evaluate the formula while reading the database records.
WhilePrintingRecords Evaluate the formula while printing the database records.
EvaluateAfter(formula) Evaluate after another function has been evaluated.