Solved

User cancels report run but getting debug message box

Posted on 2008-10-24
4
260 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 - Access MVP) 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now