Hide Subreport on No Data

M

Max

Acc2007. Have a subreport built on a query, linked to the main report on the
ID field. If there is no data in the subreport, would like to hide it. Have
tried this code in the No Data event of the subreport, but it isn't working:

Reports!MainReport!MySubReport.Visible = False
Reports!MainReport!LabelRP.Visible = False
(where LabelRP is in the main report)

Any help will be greatly appreciated. Thanks.
 
D

Duane Hookom

If you want to hide something in the main report based on no records in the
subreport, you can use the HasData property of the subreport. I would use a
text box with a control source like:

=IIf(sbrptCtrl.Report.HasData, "Label Caption",Null)
 
M

Max

Duane,

Your solution worked for a text box on the main report. I also want to hide
the subreport itself on no data. Help gives the following statement:

Me!SubReportControl.Visible = Me!SubReportControl.Report.HasData

Does this mean I have to have a statement for each control on the subreport?
What event of the main or sub form should have these statements?
Is there a statement that would hide the entire subreport on no data? If so,
what event should it be in?

Thanks again.
 
D

Duane Hookom

I am surprised that a subreport that has no data appears. Normally we get
questions from users who have a subreport with no data that they want to see
in the main report but the subreport is automatically invisible if no records
are to be rendered.

How are you seeing a subreport when there are no records in the subreport?
What is there to see?
 
M

Max

Duane,

I get the column headings (labels) and one field shows with a value that is
the "new" record you always see at the end of a query. If there are no
records in the query that is the recordsource for the subreport, I do not
want to see the labels or the fields.

Hope this explains it. Hope you can help.
 
D

Duane Hookom

Your subreport must not be a subreport. Is it actually a subform? I have
never heard of a subreport that contains no records that shows anything on
the main report.
 
M

Max

Duane,

I checked - it is a subreport. Is there a way I can email you the database?

Hope the answer is yes!
 
D

Duane Hookom

I expect your subreport has a record in it. You can test this by displaying
the Report (not the Page) Header section and adding a text box in it:
Control Source: =Count(*)
What so you see in the text box?
 
M

Max

It all seems to be working now. Thanks for hanging in there with me on this
LONG one....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top