Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

6.03 Boolean AND and OR operators

From what you have seen so far, the Select Expert is a very helpful tool for selecting one or more fields using the basic comparison operators. This is probably adequate for many of the reports you write. But what about the other reports where you need to build more complex filtering criteria? For those reports, there is the Formula Editor. The Formula Editor is described in complete detail in Chapter 7, but here is a summary of how to use it.

The Formula Editor lets you use Crystal syntax, the built-in programming language, to create sophisticated selection formulas. There is a large library of functions to choose from for building a selection formula. A simple example is when you don’t want to use the Select Expert’s default of requiring a field to match all the criteria selected. You can change the formula so that rather than use the default Boolean AND to join the conditions, it uses Boolean OR. Another example is rather than selecting a range of records based upon customer name, select the records based upon the first character of the customer name. This would let you choose all the customers with names starting with the letter “B”.

When opening the Formula Editor from within the Select Expert, you are only given the option of using Crystal syntax as the programming language. As you will see in Chapter 7, Crystal Reports also gives you the option of using Basic syntax, which is very similar to VB.NET. Unfortunately, the Formula Editor requires using Crystal syntax.

There are two ways to enter a custom formula. The first way is to click on the Show Formula button. This shows the existing formula built using the fields already selected. You can change this formula directly so that it matches the selection criteria you need. If you can’t remember the different built-in functions well enough to type them in directly, click on the Formula Editor button. This brings up the Formula Editor dialog box (discussed in Chapter 7) and you can use it as a reference tool to build the formula. The second way to enter a formula is to click on the comparison list dropdown box and at the very bottom is an item called formula:. Clicking on this item changes the right side to a multi-line text box that lets you type a formula from scratch.

Crystal Reports raises the error “Failed to open rowset” when a record selection formula performs an empty string comparison on a field with a null value.
Formula = {table.field} <> “”
To correct this you also have to check for null values.
Formula = not(isnull({table.field})) AND {table.field} <> “”