Hide error 2501

mbamber

Registered User.
Local time
Today, 23:48
Joined
Jul 30, 2013
Messages
31
Hi all,

I'm sure this is on the web somewhere, but I just can't seem to find it!

I currently have a simple piece of code:

Code:
Private Sub PDF_Click()
DoCmd.OutputTo acOutputReport, , ".pdf", , -1, , 0, acExportQualityPrint
End Sub

My problem is that when the save as dialogue appears, if the user then clicks either close or cancel, error 2501 appears - "The OutputTo action was canceled."

Is it possible to just hide this error if it appears and if so, how could I do this?

TIA
 
How about adding a Proper Error Handler? Something along the lines of..
Code:
Private Sub PDF_Click()
On Error GoTo errHandler
    DoCmd.OutputTo acOutputReport, , ".pdf", , -1, , 0, acExportQualityPrint
errExit:
    Exit Sub
errHandler:
    If Err.Number <> 2501 Then MsgBox "Error - " & Err.Number & ": " & Err.Description, vbCritical, "Fatal Error"
    Resume errExit
End Sub
 
Fantastic, I knew it would be simple for someone; just not me!
 
Glad to help, bookmark Chip Pearson's link on Error Handling.. It is a good place to start learning about good error handling techniques.. Good Luck.. :)
 

Users who are viewing this thread

Back
Top Bottom