Repost: Avoid opening blank report when no data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Windows XP, MS Access 2K
====================
Hi,

I'd posted a question here last week:

http://support.microsoft.com/newsgr...75b2adc68568&lang=en&cr=US&sloc=en-us&m=1&p=1

which I'm still struggling to solve. Basically, when I open a report from a
form when there is no data, the report opens with a blank page instead of
displaying the "No data" message and not opening the report. I DO have the
code in the "No Data" event of the report, but still the report opens with a
blank page.

Will appreciate if someone can point me in the right direction.

Thanks!

-Amit
 
Windows XP, MS Access 2K
====================
Hi,

I'd posted a question here last week:

http://support.microsoft.com/newsgr...75b2adc68568&lang=en&cr=US&sloc=en-us&m=1&p=1

which I'm still struggling to solve. Basically, when I open a report from a
form when there is no data, the report opens with a blank page instead of
displaying the "No data" message and not opening the report. I DO have the
code in the "No Data" event of the report, but still the report opens with a
blank page.

Will appreciate if someone can point me in the right direction.

Thanks!

-Amit

Why didn't you include the OnNoData code here?
 
Oh, sorry about that.
Here's the code in the No Data event of the report:
=======================
Msgbox "No data to display."
Cancel=True
=======================

-Amit
 
Quote from your original post

I have an unbound report that contains 3 other reports that are bound to
separate queries. I open the main report from a form after specifying
criteria.

Everything is working the way it should when there is data to display,
except when there is no data to display, the report opens with a blank page.

I have the following in the No Data event of the main report as well as the
3 other reports included on the main report:
msgbox "No data to display."
cancel=true

Am I missing something here? In other reports, when there is no data, this
works by displaying the message and not opening the report.

Would appreciate some help on this so that if there is no data to display
(meaning all the 3 reports have no data), then instead of opening a blank
report, a message is displayed.


End quote

I think that if your report is unbound and you are using subreports that you
will have to check the hasdata property of each subreport and if they are
all false, then you will have to cancel the report. I don't have time to
test this, but I would attempt to do this in the On Open event of the
report. If you can't test the subreports in the on open event, then you
would have to create a recordset based on each sub-report recordsource
(duplicating the queries) and check the record count of each recordset.
 
John Spencer said:
Quote from your original post

I have an unbound report that contains 3 other reports that are bound to
separate queries. I open the main report from a form after specifying
criteria.

Everything is working the way it should when there is data to display,
except when there is no data to display, the report opens with a blank page.

I have the following in the No Data event of the main report as well as the
3 other reports included on the main report:
msgbox "No data to display."
cancel=true

Am I missing something here? In other reports, when there is no data, this
works by displaying the message and not opening the report.

Would appreciate some help on this so that if there is no data to display
(meaning all the 3 reports have no data), then instead of opening a blank
report, a message is displayed.


End quote

I think that if your report is unbound and you are using subreports that you
will have to check the hasdata property of each subreport and if they are
all false, then you will have to cancel the report. I don't have time to
test this, but I would attempt to do this in the On Open event of the
report. If you can't test the subreports in the on open event, then you
would have to create a recordset based on each sub-report recordsource
(duplicating the queries) and check the record count of each recordset.

Hi John,

Thanks for your respone. Yes, that did the trick. Excellent idea.
I actually added a button on the form to open the report, and make it
visible only if there is data in the subforms that are displayed on the form.
The report is based on the subforms, so it works out fine.

Cheers,
-Amit
 

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

Back
Top