• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

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
    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
1 Solution
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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.
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
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".

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.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now