Error Handling Help Please

ddrew

seasoned user
Local time
Today, 17:57
Joined
Jan 26, 2003
Messages
911
I have a form with a button (btn_Print) for printing a report. It workd fine, except for one thing, when the button is pressed, the report pops open and the Microsoft Windows Print box appears, this in itself is OK. The problem comes when the user chooses to cancel the print.

They press the cancel button on the Microsoft Windows print screen and the following mesage appears.

"The RunCommand action was canceled".

How can I stop this fom happening please?
 
OK I understand that but what function should I attach the error handling code to? The cancel button is on the Microsoft Windows Print box so cant access that! Do I put it in the btn_Print code on my form? I already have code there, with some error handling.

Code:
Private Sub btn_Print_Click()
    On Error GoTo btn_Print_Click_Err

    DoCmd.OpenReport "rpt_01_Profile", acViewPreview, "", "", acNormal
    DoCmd.RunCommand acCmdPrint


btn_Print_Click_Exit:
    Exit Sub

btn_Print_Click_Err:
    MsgBox Error$
    Resume btn_Print_Click_Exit

End Sub
 
Adapt this code:
Code:
Private Sub Command9_Click()
On Error GoTo ErrorHandler

    DoCmd.OpenReport "Sol1", acViewPreview
    DoCmd.RunCommand acCmdPrint

Ex:

Exit Sub

ErrorHandler:
    Select Case Err.Number
        Case 2501
            MsgBox "Cancel was selected"
        Case Else
            MsgBox "Unknow error"
    End Select

    Resume Ex

End Sub
 

Users who are viewing this thread

Back
Top Bottom