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.

4 comments:

  1. works for me...
    it will be great if you also type code here instead of only image representation.
    But it works for me. Thanks.
    I want to do following things in my project
    1. I do not want to draw line if it is in first row of my crystal report.
    2. I want space between text upper line and text.

    ReplyDelete
    Replies
    1. Hi,
      Good to here that. the sole purpose to attach image to show everything clearly in the screen. Can you elaborate your question in more detail?

      Delete
    2. Hi,
      I am preparing a report,which have following rows and data represent like :-

      standarno| grp| grp name|testname|catcode
      amd | tst |mt | mt1 |001
      | mt2 |001
      | mt3 |002

      there is border between headline and data like for group name column , data in which text object has top border property similarly for testname column data i have use text object border property to draw line bottom of object so after each mt1,mt2 there is line.
      Secondly whole report is bound with BOX object.
      So i have do two thing.
      firstly i want to show blank line or gap between border and text of text object for tst and m1.
      2. At the end of the page for one field data (mt3) i have to disable bottom border because due to box line there will be two line display.

      Can you please help that is it possible or not?


      Delete
  2. I am using crystal report 10, I used one vertical line in my report its start from Group header to group footer, I want show this vertical line only in first page, after that it should be suppress.
    Any buddy can help me regarding..

    ReplyDelete