Access 2007: Report>OnNoData Function

B

bh

In access 2000, I was able to use "docmd.cancel" after a message box in the
OnNoData function to get a message box to display, but otherwise return to
the calling form.

In Access 2007, however, this displays the message box, and then gives me an
error message on top of it. I've also tried "Cancel=True". I'm new to this
version of Access. Has something Changed, here?

Thanks in Advance
bh
 
A

Allen Browne

Using the CancelEvent action in a macro, or setting the Cancel argument to
True in code - both approaches should work in A2007.
 
B

bh

Unfortunately neither method works, that is why I posted the question. The
only workaround I can find is an "on error" trapping of error number 2501
from the form that calls the report, with a "resume next". Thanks for
trying, though.

bh
 
A

Allen Browne

In any version of Access, when you use OpenReport() and the report does not
open (e.g. the user cancels it because it took ages to open, or the Open
event was cancelled, or the NoData event was cancelled), Access has the good
sense to notify you that it did not proceed so the code does not merrily
execute on the assumption that the report is now open. Error 2501 is how it
does this. Error trapping is the correct solution.

What I personally do is to use my own function to open reports. It returns
True the report opened, False if it did not. Therefore you can just:
Call OpenTheReport("Report1")
if you don't care, without having to trap for error 2501 everywhere.

The function also has a few other modifications, which may or may not be
useful for you. If it's any use, you're welcome to it here:
http://allenbrowne.com/AppPrintMgtCode.html#OpenTheReport
 

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

Similar Threads


Top