Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Location
    Sacramento, CA
    Posts
    120

    Unanswered: Error 2501 You cancelled...

    Scenario:

    Simple form
    Simple query (with a parameter)
    Simple report (based on query)
    Simple macro (To open report)

    Command button on form - triggers macro
    Parameter pops up
    User presses cancel
    Receives the error 2501 "You cancelled the action etc....

    I know I need to trap this error, but I forgot where to
    put the error handler??
    In the report ? Where?

    I actually answered this for someone a long time ago, and I can't find the post (or my answer!!)

    Thank you for helping out!

    Michael

  2. #2
    Join Date
    Apr 2003
    Location
    Evansville, Indiana
    Posts
    76

    Lightbulb

    I don't know for sure which event to put the code in, but I'm thinking it will be an event in the Report object. Try this...
    Code:
    Private Sub Report_Error(DataErr As Integer, Response As Integer)
       Select Case DataErr
          Case 2501
             ' try each one of these lines to see what works.
             Resume Next
             DoCmd.Close acReport, Me.Name
             ' you may want to try setting the Response variable to something too...I'm not sure how to use it though.
          Case n
             ' trap for some other numbers if you want...
          Case Else
             MsgBox "An unexpected error occured..."
       End Select
    End Sub
    HTH!

    Kael

  3. #3
    Join Date
    Mar 2002
    Location
    Sacramento, CA
    Posts
    120
    Thanks Kael !

    Here is what I wound up with (The code was actually in a form module - DoCmd Open Report etc....)

    Private Sub cmdWhatEver_Click()
    On Error GoTo Err_cmdWhatEver_Click

    DoCmd.OpenReport "My Report Name", acViewPreview

    Exit_cmdWhatEver_Click:
    Exit Sub

    Err_cmdWhatEver_Click:

    If Err.Number = "2501" Then
    Exit Sub
    Else
    MsgBox Err.Description
    Resume Exit_cmdWhatEver_Click
    End If


    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •