Solved

User cancels report run but getting debug message box

Posted on 2008-10-24
4
264 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
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

680 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