Why am I no longer trapping Access Runtime Error 2501?

I am developing an Access 2007 "project" (.adp) as a front-end to a SQL Server 2005 Express database.

All of a sudden I seem to be getting Access Runtime Error 2501 popping up when a user decides to "Cancel" a Report that they have just launched. I'm sure that the code I have pasted below, which I have used throughout my application for the past couple of years, trapped this error and gave my own "elegant" cancelled message.

Is there any reason why this error should now be slipping through my "error trapping net"? Is there some sort of global setting that might have changed?

I have read a few posts on this same topic, but none have been able to help.

Thanks & regards. Colin.

My code :

Private Sub cmdPrint_Click()
    ' Print the Stock Dimensions Options
   
On Error GoTo HandleError

    Dim strReportName As String
   
    strReportName = "rptStockDimensionOptions"
   
    ' Open the report in Preview View
    DoCmd.OpenReport strReportName, acViewPreview
           
    DoEvents
    ReFocusOnReport (strReportName)
    DoCmd.RunCommand acCmdPrint
    DoCmd.Close acReport, strReportName
   
    Exit Sub
   
HandleError:
     'If the user clicks "cancel" in the Print Dialog box.
    If Err.Number = 2501 Then
        genASADMessage "The report has been cancelled."
        DoCmd.Close acReport, strReportName
    Else
        genErrorHandler Err.Number, Err.DESCRIPTION, ThisFormName, "cmdPrint_Click"
    End If
   
    Exit Sub
End Sub ' cmdPrint_Click
colinasadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Are you SURE you are getting 2501?  As I recall, there is another error number that can occasionally occur, which means the same thing.

Put a breakpoint at that location and confirm the actual error number.

Also ... ReFocusOnReport (strReportName)  ... this sub for function call  is causing your cmdPrint sub to lose scope ... and that might be an issue.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Open up the VBA editor window and click on tools, options, then the general tab.

Make sure error trapping is set to "Break on Unhandled Errors".

Jim.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
colinasadAuthor Commented:
Thanks very much for the prompt replies, and Jim's solution was right on the button.
My "Error Trapping" setting was set at "Break on All Errors". When I changed that to "Break on Unhandled Errors" normal service was resumed.
I don't know why that setting would have been changed. I guess there is every chance I was told to change it when investigating something else in the past without appreciating all the implications.
Any thanks again for a swift solution.
Colin.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.