Run time error 2501 openreport action was cancelled

D

Damon Heron

First let me start by saying I googled this question, which is probably a
common one, and tried everything without success.
When I open a report with no data from my form "frmAllReports" it goes to
the report open and cancels on no data. Fine so far. Then when it returns
I get the error msg. Here is my form code:
Public Sub cmdReports_Click()
On Error GoTo Err_cmdReports_Click
On Error Resume Next 'I added this on the advice of someone in newsgroup -
no help

DoCmd.OpenReport stDocName, acPreview 'stDocName is a public variable
that works fine unless no data

Exit_cmdReports_Click:
Exit Sub

Err_cmdReports_Click:
If Err.Number = 2501 Then Resume ExitHere
MsgBox "Error Number: " & Err.Number & vbCrLf & Err.Description
Resume ExitHere

End Sub

Nothing has changed with Access - it is on a single pc and the db is still
in development. Any ideas??
 
6

'69 Camaro

Hi, Damon.
Any ideas??

You don't have the ExitHere label defined, and you have several other
errors. Try:

Err_cmdReports_Click:
If Err.Number = 2501 Then GoTo ExitHere
MsgBox "Error Number: " & Err.Number & vbCrLf & Err.Description

ExitHere:
Err.Clear
End Sub


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
D

Damon Heron

Okay. I didn't do a good job of copying my code, but it wasn't working and
wouldn't work with your code either, because I discovered the real problem -
in the tools/options on the VBA screen the box "halt on all errors" was
checked, instead of "halt on unhandled errors". Once I changed that,
everything is back to normal. Now if I could just identify the gremlin that
changed it in the first place........:(

Thanks for your help.
--
Damon Heron

'69 Camaro said:
Hi, Damon.
Any ideas??

You don't have the ExitHere label defined, and you have several other
errors. Try:

Err_cmdReports_Click:
If Err.Number = 2501 Then GoTo ExitHere
MsgBox "Error Number: " & Err.Number & vbCrLf & Err.Description

ExitHere:
Err.Clear
End Sub


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 

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