By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,087 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,087 IT Pros & Developers. It's quick & easy.

Using NoData Event in Access 2003 Report

P: n/a
Hello,
I have an Access 2003 report that opens in print preview and then
maximizes upon clicking a button from a form. The OnClick event of the
button fires a macro to open the report.

How can I use the NoData event of the report to present a message box
( with vbOkayOnly) so that when the button is clicked, if the report
returns no data a message box appears, and the report never opens?

I've tried the following in code with the NoData event in a report;

Private Sub Report_NoData(Cancel As Integer)
DoCmd.CancelEvent
MsgBox "There is no data for the selected test.", vbOKOnly, "No Data"
End Sub

When the report has no data, the message box comes up, and the report
does not open, but the form maximizes. I thought that
DoCmd.CancelEvent would cancel the action of opening the report, but
that does not seem to work quite right.

The other thing I have thought about was to just set up a text box in
the report to return a count of student ID's, and if that number were
zero, close the report and show a message box.

Any ideas?

Thank you for your help!

CSDunn
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 16 Nov 2004 16:02:05 -0800, CSDunn wrote:
Hello,
I have an Access 2003 report that opens in print preview and then
maximizes upon clicking a button from a form. The OnClick event of the
button fires a macro to open the report.

How can I use the NoData event of the report to present a message box
( with vbOkayOnly) so that when the button is clicked, if the report
returns no data a message box appears, and the report never opens?

I've tried the following in code with the NoData event in a report;

Private Sub Report_NoData(Cancel As Integer)
DoCmd.CancelEvent
MsgBox "There is no data for the selected test.", vbOKOnly, "No Data"
End Sub

When the report has no data, the message box comes up, and the report
does not open, but the form maximizes. I thought that
DoCmd.CancelEvent would cancel the action of opening the report, but
that does not seem to work quite right.

The other thing I have thought about was to just set up a text box in
the report to return a count of student ID's, and if that number were
zero, close the report and show a message box.

Any ideas?

Thank you for your help!

CSDunn


Don't maximize the report from the button on the form.
Simply code the Report's Open event:
DoCmd.Maximize

To return to the un-maximized form when you close the report, code the
Report's Close Event:
DoCmd.Restore

Try the code in theReport's OnNoData event this way.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for the selected test.", vbOKOnly, "No Data"
Cancel = True
End Sub

Note: You will probably get a "You canceled this action..." error
message.
Trap Error 2501 in the command button event that opens the report.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #2

P: n/a
> I have an Access 2003 report that opens in print preview and then
maximizes upon clicking a button from a form. The OnClick event of the
button fires a macro to open the report.
So how exactly does the report get maximized?
When the report has no data, the message box comes up, and the report
does not open, but the form maximizes. I thought that
Okay, nevermind, I think I understand what's going on. It's just an
MDI thing. When there's data on the report it'll come up full screen,
but then when you close the report, the form is maximized, too, right?
That's how MDI works.
DoCmd.CancelEvent would cancel the action of opening the report, but
that does not seem to work quite right.
How can it know there's no data without opening and processing the
report...?
The other thing I have thought about was to just set up a text box in
the report to return a count of student ID's, and if that number were
zero, close the report and show a message box.


Better yet, if that number is zero, set the button's ( that opens the
report ) enabled property to false.
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.