Results 1 to 4 of 4
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Remove "OpenReport action cancelled" message from button code

    I have a button in a form which opens up a report. The report is controlled by a query that has criteria search fields. If a user presses the button and is prompted with a criteria search box but cancels out of it, access shows the message "The OpenReport action was canceled"



    Is there any way to get rid of this message from appearing? Exiting out of the criteria search box is common and this message is just one extra click. The code for the button is below. Thanks!

    Code:
    Private Sub btnOpenReport_Click()On Error GoTo btnOpenReport_Click_Err
    
    
        DoCmd.OpenReport "rptComplaints", acViewReport, "", "", acNormal
    
    
    btnOpenReport_Click_Exit:
        Exit Sub
    
    
    btnOpenReport_Click_Err:
        MsgBox Error$
        Resume btnOpenReport_Click_Exit
    
    
    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps you could replace: MsgBox Error$ with MsgBox Err.Number which will tell you the error number.
    Once you know the number you could handle the error with code If/Then using
    Resume btnOpenReport_Click_Exit when you've caught it with If/Then

    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    To expand on Bob's suggestion,
    See if this will handle it:

    Code:
    Private Sub btnOpenReport_Click()
        On Error GoTo Error_Handler
        DoCmd.OpenReport "rptComplaints", acViewReport, "", "", acNormal
    Error_Handler_Exit:
        On Error Resume Next
        Exit Sub
    Error_Handler:
        Select Case Err
            Case 2501   'ignore, user cancelled
            Case Else
                MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure btnOpenReport_Click" & "."
        End Select
        Resume Error_Handler_Exit
    End Sub

  4. #4
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by davegri View Post
    To expand on Bob's suggestion,
    See if this will handle it:

    Code:
    Private Sub btnOpenReport_Click()
        On Error GoTo Error_Handler
        DoCmd.OpenReport "rptComplaints", acViewReport, "", "", acNormal
    Error_Handler_Exit:
        On Error Resume Next
        Exit Sub
    Error_Handler:
        Select Case Err
            Case 2501   'ignore, user cancelled
            Case Else
                MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure btnOpenReport_Click" & "."
        End Select
        Resume Error_Handler_Exit
    End Sub
    That worked!! Thank you both

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 09-27-2015, 12:29 PM
  2. Replies: 4
    Last Post: 07-12-2014, 02:02 PM
  3. Replies: 3
    Last Post: 05-06-2012, 06:29 PM
  4. Replies: 0
    Last Post: 01-11-2012, 12:34 PM
  5. The OpenReport action was cancelled
    By Paul H in forum Reports
    Replies: 5
    Last Post: 11-11-2011, 02:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums