Sub Reports

  • Thread starter Thread starter dickw
  • Start date Start date
D

dickw

I have a Report with two subreports. It works fine except --

The "On No Data" event of the subreports do not trigger when the main report
is opened. I guess I could simulate this event with some code but I wonder
if there is an easy way to get the "On No Data" event for a subreport to
trigger when the subreport has no data.

Thanks.

Dick
 
Use the OnNoData event of the report that is serving as the subreport. Open
the subreport in design view and you'll see that it has the same list of
events that the other reports have.
 
Thanks for your reply.

Thats exactly what I did but nothing seems to happen. I but a msgbox line
in the OnNoData code but it never executed even when there was no data from
the underlining query.

If I open the subreport on its own, the OnNoData event triggers as I expect.

Dick
 
Sorry, not good for me to have relied on memory. You're correct it's not
firing in this situation.

What do you want to have happen if the subreport has no data? Likely that
result will need to be programmed into the main report somehow...if you just
don't want the subreport to show, you should be able to set its CanShrink
property to yes?
 
I was going to make an explanatory note visible in the case of no data.
It's not a big deal but I thought it would be nice to let users know why no
data was showing up. Since I am using a query to access the data, I guess I
can write some code to detect if there are no records returned but that
seemed a lot of work if the OnNoData event could be made to trigger.

Thanks for your help.

Dick
 
OK - I did a bit of research, and I believe you may be able to use the
HasData property of the subreport. Check that property's value for the
subreport ("Me.SubreportName.Report.HasData"): if = -1, subreport is bound
to a recordsource and it has data; if = 0, subreport is bound to a
recordsource and has no data; and if = 1, subreport is not bound to a
recordsource.
 
I used the HasData property in the main report's OnFormat event and it works
great.

Thanks a lot. Your help is appreciated.

Dick
 
You're welcome.

--
Ken Snell
<MS ACCESS MVP>

dickw said:
I used the HasData property in the main report's OnFormat event and it works
great.

Thanks a lot. Your help is appreciated.

Dick
 
Back
Top