Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Location
    New York, New York
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error message on cancel report (2000)

    I have a report that is opened by a command button on a form that filters the report according to any criteria that has been entered by the user.

    In the report's NoData event I have message box saying that there are no matching records, and then I cancel the event. When the event fires the message box displays fine, but I get a second box telling me the OpenReport action was cancelled. I have SetWarnings to false in both the code behind the command button and the NoData event, but I still receive the error message. When I click 'debug' I am taken to the OpenReport command in the button code, and I can see the 'Docmd.SetWarnings False' in the line right above it.

    Anyone know what I'm missing?

    Thanks,
    Karl

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

    Re: error message on cancel report (2000)

    It is easy to trap this error. The error that occurs when an action is cancelled has error number 2501. The code could look like this (with the appropriate names substituted, of course):

    Private Sub cmdReport_Click()
    On Error GoTo ErrHandler
    DoCmd.OpenReport "rptSomething", acViewPreview, , "WhereCondition"
    Exit Sub

    ErrHandler:
    ' Don't display error message if action was cancelled.
    If Err.Number <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    If you use code like this in several places in your database, you can define a constant in a standard module:

    Public Const conErrCancelled = 2501

    and use this in your code (If Err.Number <> conErrCancelled Then)

  3. #3
    Star Lounger
    Join Date
    Sep 2002
    Location
    New York, New York
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error message on cancel report (2000)

    Thanks Hans, worked like a charm. -Karl

Posting Permissions

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