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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to supress a subreport conditionally? 1

Status
Not open for further replies.

yehong

Programmer
Sep 22, 2003
291
0
0
US
I have a subreport in that group footer section of my main report, say in section GF1b. The subreport is linked with the main report via employee id. The main report passes ID to the subreport and subreport returns results based upon that ID.
Here is the problem, there is a shared variable at the footer of the subreport that stores count of records. Now I have a formula on the main report that receives that value of count and I have a conditional supress function for GF1b section. The function checks the value of the the count and if count =0 then it should supress whole section, otherwise show the section. But what is happening is it is supressing the whole section even if count is 4, or 5 or >0.
My formula on main report is returning correct count.

Any idea why whole section gets supressed even if the count is >0?

I am using CR8.5 with SQL Server.
 
Your formula in your main report that "receives" the value of the count from your subreport must be in a section below the section your subreport is in for it to correctly "receive" the count value in the shared variable. Since you are trying to use the shared variable in the main report in the SAME section as the subreport is placed in, that is why it isn't working.

There may be another way to accomplish to some degree what you are trying to do (although you may have to put up with a small amount of blank space on your report but read below and perhaps one of the methods below will help)

You didn't mention which version of Crystal you are using.

If you are using version 9, you can right click on your subreport object and there is a formatting option to suppress the subreport if it is blank. You may need to conditionally format all the sections in your subreport to suppress when there are ZERO records returned (you should be able to use an IsNull() test to do this on all the subreport sections since if you get ZERO records the test for IsNull at any point in the report will be true) so that Crystal will "see" your subreport as being blank and therefore suppress it.

For version 8.5 there isn't a "suppress blank subreport" format option so you may have to use the method described above to suppress the sections in the subreport but you may have to put up with some blank space in the main report because you won't be able to suppress the section the subreport is in.

Hope this helps.

MRudolph
 
Hi Rudolph,
I have placed the shared variable below the section where I have the subreport. How would I supress the subreport based upon the shared variable that gets its value after the subreport has to be evaluated first? I meant subreport has to evluate first to get the count, then if there is a section below to the section of shared variable, that section can definitely be suppressed, but section above shared variable can not. Any thoughts?

Also another question unrelated to above problem I am noticing is that I have conditionally suppressed some rows in the details section. I am seeing big gaps when some rows get suppressed. Any fix to that?

I am using CR8.5 with SQL Server2000.
 
You can make the subreport object as small as possible (and remove the borders) and decide to live with the white space when the count = 0 (the subreport is formatted to "can grow" by default, so will expand when the subreport count <> 0). Or you can save the subreport using file->"Save subreport as" and then do the following:

Insert a second group header section GH#1b and import the newly saved subreport there, and link it the same way as you did the original subreport. Go into the subreport to the section expert and suppress ALL sections of the subreport. In the main report, select the subreport and resize it to make it narrow. Remove the subreport borders (format subreports->borders->line style->none). In the subreport, create a shared variable {@x}:

whileprintingrecords;
shared numbervar x := count({table.field});

Place this on the subreport canvas.

Next, in the main report, go to the section expert (format->section)->GH#1a and check "Underlay following sections". This way the space taken up by the newly added subreport will be under the GH#1a section.

In the main report create a formula:

//{@reset} to be placed in GH#1a and suppressed (format field->
//common->suppress):
whileprintingrecords;
shared numbervar x := 0;

Next go to the section expert in the main report->GF#1
(where the original subreport is located) and enter:

whileprintingrecords;
shared numbervar x = 0;

While in the section expert, also highlight details->check "Suppress blank section" to address your second problem of extra detail space when using conditional suppression.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top