Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

7.05 Printing Checkboxes

Printing Checkboxes

Displaying checkboxes on a report presents a new challenge. Checkboxes represent when a Boolean value is either true or false. But Crystal Reports doesn’t have a way to print checkboxes. There are other ways to display a Boolean constant. For example, you can display the words Yes/No or True/False by right-clicking on the field and selecting Format field. The dialog box displays a drop-down box that lets you select how you want the data to be displayed (Yes/No, True/False, etc.).

Displaying Boolean values as a checkbox requires a little more creativity. You have to trick Crystal Reports into printing checkboxes by switching to the Wingdings font. There are a variety of interesting characters in the Wingdings font. But five of them can be used for displaying checkboxes. Figure 7-9 shows some of the Wingdings characters available.



Figure 7-9. Wingdings control characters.

In the last two rows are the checkboxes. There are four types to choose from as well as an empty checkbox. To use these characters in your report you have to create a formula that uses the ASCII code for the checkbox you want to display and return the appropriate character. The only problem with this idea is that it is very difficult to determine the correct ASCII code. In previous versions of MS Windows, you could open the Character Map and it showed you the ASCII code at the bottom. You could easily type this number into your formulas. But with Windows XP, they stopped showing the ASCII code and now they only show the Hexadecimal equivalent. I don’t know why Microsoft implemented this “feature” because it’s very difficult to convert the hexadecimal number to a decimal. So rather than make you figure out the math, I’m going to give you a cheat-sheet to use for your reports. Table 7-6 shows each checkbox and its ASCII equivalent.

Table 7-6. The Wingdings checkboxes and their ASCII equivalents.

Checkbox ASCII Value

168

251

252

253

254

To display a checkbox on the report, create a new formula field and insert the following Basic syntax formula.

If {Table.Field} = True Then
‘Display the checkbox of your choice here
Formula = Chr(254)
Else
‘Display empty checkbox
Formula = Chr(168)
End If

This formula tests a field to see if it is true. If so, it returns the control character 254 (a checked box). If it is false, it returns the control character 168 (an empty checkbox). Save the formula and close the Formula Workshop.

Drag this formula from the Field Explorer onto the report. Finally, change the font to be Wingdings by right-clicking on the field and selecting Format Object. Click on the Font tab and use the dropdown box to select the Wingdings font. Save the report and preview it to see the checkbox displayed.

I recommend using a font that is two point sizes larger than the font size of the rest of the report text. The Wingdings font is slightly smaller than regular text and increasing its size makes it easier to see. You should experiment with the font size to see what suits your tastes.

The Wingdings font has lots of unusual characters in it. You can use any of these characters in your report to print interesting graphics. For example, you might want to print a telephone graphic in the header of the phone number column and an envelope in the email column. You could print a time bomb on a row that requires immediate attention. Getting creative with the Wingdings font lets you have a little fun with a report and still keep a professional image.