Error: "The OpenReport action was cancelled. OK"

A

Andy

I created the command button using the command button wizard. My "Preview
Report" command button on my form quit working and I am still trying to
figure out what happened. In the meantime, I am curious where the Access
coding is that appears inthe message box upon the error occurring. When the
error occurs, I get a message box that says "The OpenReport action was
cancelled. OK" I know I can set that message myself but where is this
"automatic/already coded by Microsoft" message?

Thanks.

Andy

Private Sub cmdPreviewReport_Click()
On Error GoTo Err_cmdPreviewReport_Click

Dim stDocName As String

stDocName = "repCostTotalbyOPR"
docmd.OpenReport stDocName, acPreview

Exit_cmdPreviewReport_Click:
Exit Sub

Err_cmdPreviewReport_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewReport_Click
 
C

Carl Rapson

That message is in the Err.Description variable. You will usually see that
message when the Report_Open event is cancelled for some reason. To avoid
it, trap for Err.Number=2501. For example:

Err_cmdPreviewReport_Click:
If Err.Number <> 2501 Then MsgBox Err.Description

HTH,

Carl Rapson
 
C

Carl Rapson

Err is a system-supplied object that contains information about the last
error that occurred. You can look at the value of Err.Number at any time; it
will usually be zero. In the case you're describing, when the Report_Open
event is cancelled, Err.Number is set to 2501 and Err.Description is set to
the description of error 2501. All of this is done automatically, but you
still need to look at the Err object yourself. If you use the default error
handling, you will get a message box any time there is an error (Err.Number
is not zero). You can trap the errors and use your own message boxes by
adding the line

On Error Resume Next

just before any action that mikght have an error (DoCmd.OpenReport, for
example). Then check the value of Err.Number right after the call.

HTH,

Carl
 
A

Andy

Hi Carl,

Thanks for the help. It does explain things for me. I am always curious,
though, to know how things work. I was wondering if Err was something that
was settable by the user but it sounds to me like it is a hardcoded part of
"Access" or the Microsoft Jet engine. Again, thanks for the info. I found
this explanation interesting.

Andy
 

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