Access 2007: Report>OnNoData Function

  • Thread starter Thread starter bh
  • Start date Start date
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
 
Using the CancelEvent action in a macro, or setting the Cancel argument to
True in code - both approaches should work in A2007.
 
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
 
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
 
Back
Top