Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OpenReport cancelled (2003 (SP2))

    I've stopped a report from opening, where there is no data, but when this happens a message box error appears stating;
    "The OpenReport action was canceled"

    I've searched the forum & come up with trapping the error (in the error handler), but the message box still appears?

    Here's what I'm using;
    Report_NoData_Exit:
    Exit Sub

    Report_NoData_Err:
    If Error = 2501 Then
    Resume Report_NoData_Exit
    'ignore it
    Else
    MsgBox Error$
    End If

    Any ideas on how I should be doing this?

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

    Re: OpenReport cancelled (2003 (SP2))

    Where did you put this error handler?

  3. #3
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenReport cancelled (2003 (SP2))

    Well it's such a simple bit of code. Here's the lot of it;

    Private Sub Report_NoData(Cancel As Integer)
    On Error GoTo Report_NoData_Err

    MsgBox trMsgNoDataForReport, vbInformation, "No Data"
    Cancel = True

    Report_NoData_Exit:
    Exit Sub

    Report_NoData_Err:
    If Error = 2501 Then
    Resume Report_NoData_Exit
    'ignore it
    Else
    MsgBox Error$
    End If

    End Sub

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

    Re: OpenReport cancelled (2003 (SP2))

    That's not the correct place. You should put the error handler in the code that opens the report, for example the On Click event procedure of a command button on a form. The following code belongs to a command button cmdSalesReport that opens the report rptSales:

    Private Sub cmdSalesReport_Click()
    On Error GoTo ErrHandler
    ' Open report
    DoCmd.OpenReport "rptSales", acViewPreview
    Exit Sub

    ErrHandler:
    If Err = 2501 Them
    ' OpenReport was canceled - ignore
    Else
    ' Display error message
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

  5. #5
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenReport cancelled (2003 (SP2))

    You can tell I'm new to this, can't you <img src=/S/confused3.gif border=0 alt=confused3 width=45 height=45>

    Cheers Hans

Posting Permissions

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