Why am I no longer trapping Access Runtime Error 2501?

Posted on 2014-08-06
Last Modified: 2014-08-06
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
    ReFocusOnReport (strReportName)
    DoCmd.RunCommand acCmdPrint
    DoCmd.Close acReport, strReportName
    Exit Sub
     '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
        genErrorHandler Err.Number, Err.DESCRIPTION, ThisFormName, "cmdPrint_Click"
    End If
    Exit Sub
End Sub ' cmdPrint_Click
Question by:colinasad
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    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.
    LVL 56

    Accepted Solution

    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".


    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now