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!

Suppressing a subreport 1

Status
Not open for further replies.

Rena

Programmer
May 24, 2000
69
US
How do you suppress a subreport when there is no data to be displayed? I have turned on the "Suppress Blank Section" in the subreport - didn't work. I have turned on the "Suppress Blank Section" in the main report - didn't work. I have tried creating a variable in the subreport that is passed back to the main report and suppressed when that variable "IsNull" - didn't work. I have run out of ideas. Any other suggestions?

Thanks!
Rena
 
What I did to solve such problem is to suppress all sections in the subreport. That would make the subreport "suppressed" in the main report. Now, you can pass any variable in the subreport and pass it to the main report using the "Shared" type, for example:
Create a formula "InSubreport" in the subreport with the following code:

WhilePrintingRecords;
Shared NumberVar FromSubreport;
FromSubreport := {@Output}

To use that variable "FromSubreport", just create a formula "InMainReport" in the main report and write its code as follows:

WhilePrintingRecords;
Shared NumberVar FromSubreport;
FromSubreport

Now, add the formula "InMainReport" in the main report to display the variable "FromSubreport" in the main report.
 
I think the best choice depends on whether you need to conditionally suppress the subreport object, which requires a more elaborate kludge. Because the shared variable value is only set by the subreport when the subreport object is called (printed), Crystal has by then committed to printing the subreport object, so you can't use a shared variable value to suppress a subreport object conditionally.
If I understand you correctly, what you are doing is always suppressing the subreport, but extracting information from it using shared variables. For simple subreports, this would be an excellent alternative.
 
Thanks for both suggestions. I checked out the web site that MalcolmW suggested and thought I would let you know how it turned out.

The Knowledge Base solution is for CRW 5 so I made some changes to make it CRW 8. In the duplicate subreport, instead of using the StoreBooleanVar and FetchBooleanVar I set up a shared boolean variable that I set to true or false. Then in the main report I picked up that shared variable. I put the duplicate subreport and the formula that held the shared variable in a pre-existing GroupHeader2 line. Since I couldn't suppress this subreport (or it won't work) I made both the subreport and it's appearance on the main report as small as possible and set the borders to none. This did not completely remove all traces of the duplicate supreport (the top of the T in true still showed as a dash). So I lined up this mark with a literal on the report so you can't see it. I felt like I had to jump through a lot of hoops but at least I got it to work. Hopefully this will help somebody else in the future.
 
Congrats - that is one ugly way to get rid of subreports - I'm amazed that there isn't a better way that Crystal suggests.
Another kludge.
You might be able to get rid of your character trace by changing the width of the subreport to say 6 inches, openning up the subreport and putting the field with the character on the right side, then in the main report changing the width to say 1 inch (or less). That way the character will not be in the "printing range" of the subreport.
 
Thanks MalcolmW. That worked great!!

I had to make another change. When I tested this subreport supression change with a selection that should have printed the subreport, I didn't get any data. So I had to take the duplicate subreport and put it in the detail a section (the subreport that I need to conditionally supress is in detail b). When I had it in the group header 2 it didn't have the data necessary to work right.
 
an easier way is to create a field in your main report that can be used to determine if the subreport will be blank.
For example, your main report uses:
SELECT id, Name
FROM Authors

And your subreport uses:
SELECT BookTitle, PubDate FROM Books WHERE AuthId = ??

You can add to your main query to make it like this:
SELECT id, Name
,(SELECT COUNT(*) FROM Books WHERE AuthId = Authors.Id) AS Count_Books
FROM Authors

Then select Format Subreport and enter:
{Authors.Count_Books} = 0

Then suppress the blank section.
-Adam T. Courtney
Stratagem, Inc.
 
If you want to make a subreport completely invisible, use my 'stealth subreport' technique. I put it in my last newsletter:

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
I've had a lot of luck suppressing subreports only when there is no data to show. In the subreport, I determine what the main field that I'm looking for is - if it's not there, that means there was no data. Then I conditionally suppress each section in that subreport with the isnull().

I then make the subreport section as small as possible on the main report. I know this adds some space, but for my reports that helps anyway.

I found that Kbase article long after I had done this on a detailed report with 13 subreports and never bothered to go back.
 
thanks. my issue is that i don't want to show the subreport at all. i'm only grabbing the amount from it, assigning it to a variable, and then doing a calculation on it. so i don't ever want the actual subreport to show.
 
The stealth technique won't work if the subreports are back to back. What section is your subreport in? Is there anything that prints between one subreport and the next? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
i have details a, b, and c. a is suppressed, b is where the subreport is, c is also suppressed
 
So there isn't anything that prints between one subreport and the next? You can't use the stealth technique.

Can you combine the detail subreports into one larger subreport per group that gathers all of the information at once? You might be able to move the processing of the subreport values to the detail band of the larger subreport. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Yes, but it runs multiple times per report (possibly per group). Instead of running it at the detail level, can you run one subreport that gets all of the information for the whole group/report. That is only way you will be able to use the stealth technique, and that is the only way to run a subreport invisibly. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Edit the subreport and select FILE/REPORT OPTIONS/Suppress Printing If No Records

Return to the Main Report and suppress the section where the subreport appears if it is blank.

That's it.
 
Dond12 - I tried your method and the subreport still will still show. I assume you are using 'suppress blank section' in the main report?

Rena,
My comments have wandered because I was confusing your thread with another. The best you can do is to make it small. There is no way I know to cleanly suppress blank subreports. Sorry. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top