Do not display subreport if no data

dmvg2

New member
Local time
Today, 09:26
Joined
Mar 21, 2007
Messages
2
Hi - newbie here!

I have studied this issue on the web but have not yet seen a solution I understand!

I have a report containing 4 subreports - these are all structured the same but are generated from 4 separate queries which all come from the same table. Let's say I have the report:

rptallthings

which has as subreports:

rptthings1subreport
rptthings2subreport
rptthings4subreport
rptthings4subreport

Each subreport has a heading (label) in "detail" under which the records generated from each query are displayed.

I need to add a control which will cause those subreports that contain no records not to display (ie in print preview) in rptallthings. At the moment where a subreport is "empty", I am getting the heading (label) followed by nothing but I still want to ensure that those subreports still show up in rptallthings if data is entered later on.

cheers, dmvg
 
In the NO DATA event of the subreport, try putting

Reports!YourReportName.Report.YourSubReportCONTAINERname.Visible = False
 
Thanks Bob. Have tried this but its now telling me that it can't find the macro "Reports!MyReportName"

I also don't understand what "ERname" means.

I might need a bit more detailed help.

cheers
 
The forum put a space there and it is

CONTAINERname

You have to change the names to fit your ACTUAL names of your forms and controls.

A subform container is the container on the main form which actually houses the form you've chosen as the subform. The container name, if the container is placed by using the subform wizard, will be the same as your subform. If you do it manually it will not be the same.

Replace YourReportName with the actual report name, putting it in square brackets if it has a space in the name
and replace YourSubReportContainerName with the actual name of your subform container.
Code:
Reports!YourReportName.Report.YourSubReportCONTAINERname.Visible = False
 
Opposite problem

Hi. Seems this is a bit of an issue, as I also cannot find a solution to this.

I have the opposite problem:

I have a report with several subreports. What I want is for the subreport Report Headers to display within my main report, even if there are no records retrieved in the DETAILS sections. At present, if there are no records, my subreports are NOT displayed. Shame we can't swap!!

I have tried Bobs solution as above, putting my form/subform names in and changing VISIBLE to YES, but this does not work.

Reports!ContactActivity.Report.ContactActivityConsultations.Visible = True

I wondered if that code was running at all, so made some deliberate errors in it to see if these were picked up. It appears it is not - that the "On No Data" event is not being triggered - even when no records are retrieved by the sub report. I wonder if I understand what "No Data" means in this context.

When I open the subreport on on its own with no data, the headings and labels etc are displayed. It is only when the subreport is opened through its parent report that nothing is displayed.

Any help would be very much appreciated.
 
Last edited:
Hi. I've scanned lots of fourms, and have not found a satisfactory solution which enabled all subreport headers and labels to displays, even if the subreport does not retrieve any data.

I have thought of a workaround. Here it is...

1) Create a dummy table with the same number of fields (all text) that the query driving your subreport displays.

2) Change the subreport select query to union itself with the dummy table, e.g.

Select fields from tables where something UNION ALL Table dummytablename;

3) In the dummy table, add a single record, putting in one of the text fields a message something like "no more records".

This means the dummy record will always be displayed, permitting your subreport to be visible in full.

The disadvantage is that the extra dummy record will always show.

Hope that is of some help.

Mat.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom