OpenReport action was cancelled

A

Allen_N

I've just been trying to debug a report that was returning no data (because a
query it depended on pointed to the wrong table), and now the bloody thing
won't even open. The line:

DoCmd.OpenReport strShowSpecialReport, acPreview

gives:

Run-time error 2501: "The OpenReport action was cancelled".

I don't know how to debug this, because the error is thrown up before I can
step into the Report_Open or Report_Activate routines. Are there particular
exceptions that can cause it?

Thanks!
 
A

Allen Browne

Add error handling to the routine that contains the OpenReport.
Don't give any message for error 2501.

If error handling is new, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

An alternative approach is to use a little wrapper function and call it to
open your reports. The return value from the function indicates if the
report opened or not. So you can just ignore the return value (if you don't
need to know), or check the return value and take appropriate action.
There's an example of such a function here:
http://allenbrowne.com/AppPrintMgtCode.html#OpenTheReport
Just omit the line that calls SetupPrinter4Report(), as you don't need that.
 
A

Allen_N

Thanks Allen.

I figured it out last night, and I don't actually think your suggestions
would have helped, in this case.

Turns out the 'Cancel' argument had been dropped from the "Function
Report_Open" statement. (This happened when I renamed the _Activate routine
to _Open, after realising I was setting the report's record source in the
wrong place.)

It would be nice if Access VBA picked up on these kinds of errors through
its syntax checking. Of course, if I were careful to use the interface the
way it was meant to be used, these bad event routine declarations wouldn't
arise, but I get lazy when I'm coding like a demon.
 

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