Thursday, September 26, 2013

Conditionally suppress a line or a box object in Crystal Reports

As of Crystal Reports 2008 there is still no option to conditionally suppress a line or a box drawing object in Crystal Reports, so the closest work-around is to use a blank Text Field.

With the text field you can use the border properties to create most lines. By using the top, bottom, left or right border line properties you can draw a single, double, dashed, or dotted line almost anywhere you want that can be conditionally suppressed and/or colored. In the following picture, i was required to draw a line on first column. In the first look, it seems that this is a box object used but it is not so. There are text objects behind Accrued Profit, Cash Out and Deferred Collection. As first column is group 1 and second column is group 2 and third one is the sum of group 2 and Total is the sum of group 1. So in this kind of display first coulmn's values were repeated with group 2 values. So first i applied some formula on the group values then to draw line I have followed the following steps:

 Here are the steps:

1- Drag some Text Object and right click on it. Select Format Text... from the context menu.



2 - Select Border tab and click any Line style option as per requirement and click its formula button on right side. 



3 - Write the following code and change accordingly




By using multiple text fields of varying sizes, you could also conditionally size the lines too. You may be able to use the size and position dialog to conditionally change the length too, but that method seems to be grayed out (unavailable) sometimes.
Horizontal lines are simpler to create with this method, but vertical lines can also be created by stacking text fields in adjacent sections.
You may have to move the text field to the back if it blocks another field, but in most cases it won't be necessary as long as your text field is empty - maybe you want some text to conditionally appear too - just insert a formula or text. The text box gives you a lot of options.