Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

asked on

User cancels report run but getting debug message box

I have a report that depends on critiera being passed at the form level.  However, if the user cancels the process when the request for a date comes up, the error message 2501 comes up.  I have code that works if the report is run directly and it works.  Howevever, the error trap does not work in this sceanrios and I am wondering how to get around it.  So, the user clicks on the button to run the report, the box requesting a date comes up and if they hit cancel, then the 2501 error box comes up.  It may be placement of the error, but I do not know where.
Private Sub boxUserManStats_Click()
Dim intCancel As Integer
DoCmd.OpenReport "rptUserManStats", acViewPreview, , "tblProductionData.Division = 'EDS' AND " & _
                                                "tblProductionData.DataSource = 'EDSManual' AND " & _
                                                "tblProductionData.UserID = '" & Me.txtUserID & "' AND " & _
                                                "tblProductionData.ActivityDate = [Enter Date in format of M/D/YYYY] "
Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
    If Err.Number = 2501 Then
        Exit Sub
    Else
        MsgBox Err.Number & ": " & Err.Description
        Resume Exit_ErrorHandler
    End If
    
End Sub

Open in new window

Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Try this - change button name, etc:

Private Sub cmdPrintApp_Click()
    On Error GoTo Err_cmdPrintApp_Click
    DoCmd.OpenReport "SomeReportName", acPreview

Exit_cmdPrintApp_Click:
    Exit Sub
Err_cmdPrintApp_Click:
    If Err.Number = 2501 then   ' You cancelled .....
         ' no action required
    Else
         MsgBox Err.Description
    End If
    Err.Clear
    Goto Exit_cmdPrintApp_Click
End Sub

mx
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sandra Smith

ASKER

I need to get some sleep.......
I am still working on the other issue as well.