Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run Time Error (2000)

    I have a command button on a form that runs a report. The report has a parameter query behind it. When the parameter comes up and you change your mind and want to cancel, I get the following error: Run Time Error 2501 - The openReport Action was cancelled. The code behind the print preview button is as follows:

    Private Sub cmdPreview_Click()
    On Error GoTo ErrHandler
    DoCmd.OpenReport "Report for Rep Search4", acViewPreview, , Me.Filter
    Exit Sub

    ErrHandler:
    If Err = 2501 Then
    ' Canceled - ignore
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    How can I prevent this error from happening? I don't want the users to get this error if they decide they don't want to run the report. This error takes them to the code.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run Time Error (2000)

    Are you sure you posted the right code? This code already contains an error handler that ignores error 2501, so the user shouldn't get an error message.

    Oh, wait - activate the Visual Basic Editor and select Tools | Options...
    Activate the General tab.
    Make sure that "Break on Unhandled Errors" is selected in the Error Trapping section. If it is set to "Break on All Errors", you'll get an error message even if you have an error handler.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run Time Error (2000)

    That was the wrong code. The code I meant to send didn't have - On Error GoTo ErrHandler. I added that and it was fine. I inadvertantly sent the code that had the right code. I must have copied the code and forgot On Error GoTo ErrHandler. Thanks for the tip about "Break on unhandled Errors". In the future if I have the right code and I get that error - I will know where to look. Thanks for all your help.

  4. #4
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run Time Error (2000)

    Hans,
    How do you remember this stuff? That was exactly the problem. Last week I was looking around for something else and stumbled open that screen without out a clue as to what the Error Trapping options meant. So I changed to Break on All Errors to see what happens. (Then I promptly forgot all about it.) Now I see what happens.

    Al always (this is beginning to sound like a broken record), thank you for your knowledge and time,

    John

Posting Permissions

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