Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report Printing Help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm opening a report from a form using doCmd.OpenReport, I wrote a function for the OnNoData event in the report which is supposed to cancel the printing if no records are found.
The function cancels the printing but a error message is displayed:
-------------------------------------
Run-Time error '2501'

The OpenReport action was Canceled.

[debug] [end]
-------------------------------------

When I hit [debug] it takes me to the exact line in the form where the OpenReport statement is... ?
can somebody help me with this??
 
You need to create an error handler in the form's event procedure. The error handler will check for error number 2501; if true, it will simply resume execution without displaying an error message. Otherwise it will let VBA display its standard error message.
Code:
    Private Sub cmdPrint_Click
        (...)
        On Error Goto ErrorHandler
        DoCmd.OpenReport "My Report", acViewNormal
        (...)
        Exit Sub
    ErrorHandler:
        If Err.Number = 2501 Then Resume Next
        Err.Raise Err.Number
    End Sub Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top