Sub Reports

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
 
K

Ken Snell

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.
 
D

dickw

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
 
K

Ken Snell

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?
 
D

dickw

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
 
K

Ken Snell

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.
 
D

dickw

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

Thanks a lot. Your help is appreciated.

Dick
 
K

Ken Snell

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
 

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