Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing subreport with no data and a header

I have a fairly simple subreport that I want to suppress when there are no records selected for it. The problem is that I have a header and footer section of this subreport with static elements in it (text boxes, lines, etc.). I have set the section containing the subreport, the subreport itself and the sections within the subreport to all be surpressed when there are no records. Yet, the subreport shows up anyway. The data section with no data is indeed suppressed but the headers and footers seem to keep the subreport visible.

Any ideas? Oh, I'm running Crystal-Reports 2011. Thanks!

like image 500
Dan Berlyoung Avatar asked Sep 19 '12 17:09

Dan Berlyoung


People also ask

What is Subreport in Crystal report?

Subreports allow you to combine unrelated reports into a single report. It is a report within a report. You can combine data that cannot be linked and present different views of the same data in a single report.

How do you use subreport in main report?

Place the formula in a main report section that is beneath the section containing the subreport. NOTE: For the shared variable to return the correct value in the main report, you must place the formula @MainFormula in a main report section that is beneath the section containing the subreport.


1 Answers

I just ran into this myself in CR2008. Here are the steps I did to make this work:

  1. Go into your subreport (by that I mean have it open in its own designer window) -> go into 'Report Options' under the 'File' menu -> select 'Suppress printing if no records'
  2. Now go back into your main report. Right-click on the subreport -> go to 'Format Subreport' -> hit the 'Subreport' tab -> check the 'Suppress Blank Subreport' checkbox.
  3. If the subreport is the only thing in the main report section, go into that section in the 'Section Editor' by right-clicking on it -> check the 'Suppress Blank Section' checkbox.

EDIT: If your subreport does return records but it is just that none are displayed then try using shared variables. To do this you need to consider the logic you're using to display the records in the subreport in the first place. This is likely whatever logic found in the detail section suppression formula, but it will depend heavily on the format of your particular subreport.

Now, initialize a shared numbervar in your subreport's report header and then increment it each time a row is displayed using the aforementioned logic.

Back in your main report, you may be able to check the value of that variable to conditionally suppress the subreport's section. I say "may" because CR may not evaluate the subreport's variables prior to looking at the suppression formula, but give it a whirl. You'll want to use the whileprintingrecords; keyword in your section suppression formula to delay its evaluation. Good luck!

like image 141
Ryan Avatar answered Sep 23 '22 12:09

Ryan