Solved

User cancels report run but getting debug message box

Posted on 2008-10-24
4
266 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75
ID: 22798322
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
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 22798329
You are missing the

On Error Goto <your error handler>

mx
0
 

Author Comment

by:ssmith94015
ID: 22798437
I need to get some sleep.......
0
 

Author Closing Comment

by:ssmith94015
ID: 31509741
I am still working on the other issue as well.  
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question