Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Printline? - Visual Studio 2010 and Crystal Reports

Status
Not open for further replies.

AustinOne

Programmer
Mar 22, 2002
59
US
I'm using Visual Studio 2010 and Crystal Reports for Visual Studio. I'm a newbie to this environment. I have searched for the answer and couldn't find it.

Is there a way to suppress the printing of an individual print line if it is blank?

Details: I have a report where in a particular section there are "mandatory" print lines and "optional" print lines, in pairs. There are approx. 30 of these. What we need to do is print each mandatory line and then, if the associated optional line is NOT blank, print it next. Else (if blank) don't print it and don't leave a blank line (in which case the next mandatory print line would print immediately next on the very next line. There is only one field in the "optional" print line, this field would be tested to see if it is blank.

The dataset/datatables containing these fields is built and populated in VB code and is then "pushed" to the CR.

So, is this possible - is there a way in the CR to suppress the printing of an individual print line if it is blank (using CR formulas or whatever)?


 
Hi,
If you place the lines in a Text Box in CR you can format the Text Box itself to suppress blank lines without leaving any blank space between the lines it does show.

(This was developed for use in Mailing Labels where not all addresses have the same # of lines, but it works regardless of the content)



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
In the section expert, highlight Details->check "suppress blank section".

-LB
 
Turkbear,

I did not realize that you could embed a field inside of a textbox! (Did I mention that I was a newbie? :))
So, I created text objects for the optional lines and as each text object was highlighted I inserted the associated field into it (the field shows up as {field_name} inside the text object). Then I did the "Format Object" on each text object container and checked "Suppress Embedded Field Blank Lines".

However, after doing this, it still did not work.

So, then I made sure that the field value was not null, but it still didn't work.

So then, in desperation, I also tried checking "Suppress If Duplicated" in each text object based on the theory that the only duplication would be those of blank fields/lines.

It STILL doesn't work. Any ideas?

Thanks

 
lbass,

Your thought about using the "Suppress Blank Section" in the Section Expert crossed my mind. However, based on my understanding of this, I would have to set up 30 (or 60?) separate sections, in other words, a section for EACH optional "don't-print-if-blank" line.
The mandatory lines and the optional lines form alternating pairs as such:

mandatory line 1
optional line 1 (don't print and don't waste a line if blank)
mandatory line 2
optional line 2 (don't print and don't waste a line if blank)
mandatory line 3
optional line 3 (don't print and don't waste a line if blank)
...etc, for 30 times...

So, you can see why I am saving this approach as a last resort (setting up that many separate sections)...

Or, am I missing something?

Thanks

 

That is actually the best way to do this. It will do exactly what you want.

However, 60 sections is a bit much. I would look into a different way to display the data, so that you don't have to do so many sections.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Aren't these optional lines already in a separate detail section? e.g., detail_a, detail_b, etc.? Then all you have to do is format each existing section to suppress blank section.

I guess I'm unclear on what you mean by "line". I guess I assumed you had maybe two detail sections, detail_a and detail_b, and that you have fields in each, and that the detail_b fields are sometimes optional. Because of the values in the fields, there might be 30 pairs of detail_a and detail_b. But now I'm just guessing. I think you should identify the fields your are using and where you are placing them (report sections) and then show a sample of how they display.

-LB
 
lbass,

Sorry if I didn't clearly explain. Generically (not necessarily in CR lingo), if you look at the report, there is a page header area, a body area, and a footer area. The problem is in the body area, where there are 30 pairs of alternating mandatory and optional lines. Each optional line only contains a single field. For sake of example, let me cut it down to say, 4 pairs instead of 30 pairs and show it like this:

XXXXXXXXXXXXXXXX1 (1st print line of body is mandatory)
YYYYYYYYYYYYYYYY2 (2nd print line optional, don't print if blank)
XXXXXXXXXXXXXXXX3 (3rd line is another mandatory line)
YYYYYYYYYYYYYYYY4 (4th print line is another optional)
XXXXXXXXXXXXXXXX5 (5th is mandatory)
YYYYYYYYYYYYYYYY6 (6th line optional)
XXXXXXXXXXXXXXXX7 (7th line is mandatory)
YYYYYYYYYYYYYYYY8 (8th line is optional)

The above is what you would see in the printed body if none of the optional line fields were blank. But, if Y2 and Y8 are NOT blank, and Y4 and Y6 ARE blank, the printed report would look like this (with no interspersed blank lines):

XXXXXXXXXXXXXXXX1
YYYYYYYYYYYYYYYY2
XXXXXXXXXXXXXXXX3
XXXXXXXXXXXXXXXX5
XXXXXXXXXXXXXXXX7
YYYYYYYYYYYYYYYY8

Notice that there are no blank lines in between.

(Sorry for the proportional spacing above; I haven't learned how to put parts of my message into a fixed font.)

Thanks
 
jebenson,

I agree, 30 (or 60) sections is a bit much.

And I don't really understand why the approach Turkbear suggested above didn't work. (?) Darn it!

The printed output format is pretty well set in stone, but I am re-thinking the approach. Since I am building the dataset / datatable in VB and pushing it to CR, maybe I can re-structure it so that there aren't any blank lines (fields) pushed to CR.

Thanks
 
Hi,
What is the spource of the data in those 'lines'?

I am a little confused by this:
AustinOne said:
created text objects for the optional lines

Created from what?

If multiple database fields are involved and concatenated, then be sure to use a TRIM() function on each field before concatenation and placing it in the Text Box..That way any empty spaces ( which can be seen as non-blank sometimes) are eliminated.





[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
In the "body" of the report, what sections are you using? Look in design mode if necessary to see what sections are used or look at the gray area to the left of the data where you should see the section name(s). For the sample data that you show above, is this one row of data? Please identify the field names and the sections they are in.

-LB
 
Turkbear,

re: your 1st question, the datasource is a dataset/datatable created in Visual Studio with the dataset designer (i.e., add new item to project, select a dataset, then configure/create the datatable columns in the dataset designer screen).

re: your 2nd question, the text object was created within the CR designer screen by dragging a text object from the CR toolbox onto the CR report design surface.

re: your 3rd item, there is only 1 database field inside the text object and it is a text/string datatype.
 
lbass,

I have not yet created any additional sections yet, as it appears that I would need to create 60 sections if I go with your approach. I have not yet tested your approach; I was holding out in hopes of getting Turkbear's approach to work, which would not require creating separate sections.

I was just using the standard "Details" section for testing Turkbear's approach.

Not sure what you mean about the gray area to the "left", as the standard section names appear in gray bars "above" each section.

Each mandatory print line in the body contains two database fields; the alternating optional print lines each contain only one database field, as discussed earlier.
 
Hi,
These 2 statements seem to contradict each other:

AustinOne said:
there is only 1 database field inside the text object and it is a text/string datatype

and to lbass:

AustinOne said:
Each mandatory print line in the body contains two database fields;

How are the 2 fields placed ( joined by concatenation ot placed separately next to each other)?

To have the method I posted have a chance to work, BOTH 'lines' need to be inside the Text Box.



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
We are not communicating, I guess, as I never suggested inserting 60 sections.

-LB
 
Turkbear,

The mandatory print lines and the optional print lines alternate, as I mentioned a couple of times before. Each mandatory print line has 2 fields, and it will print regardless - no problem there. It's the alternating optional print lines which only contain one field (which is possibly blank). This is the one that I put inside of a text object, in hopes of suppressing the print of it if it is blank.

I have since given up, and I am going a different route.

But thanks for the help.
 
Hi,
OK, but I just wanted to be sure the both lines ( the one that always prints AND the one that may not) are both inside a TEXT BOX ( not just a text object) - the Box can be formatted to not create a space for the optional line if no contents exist.



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top