Trapping the cancel of OutputTo

chrisbrookeanna

Registered User.
Local time
Today, 19:53
Joined
Apr 6, 2004
Messages
14
Im using the OutputTo function to generate a file, which works OK. However, if the user quits cancel in the file dialog box you get an error saying the OutputTo action was cancelled. How do you trap this error,
so no error box is displayed.

Thanks.
 
You need an error handler in the Sub that is calling the DoCmd.OutputTo method.

I tested for the exact error number that is generated when a user cancels the output and found that it is 2501, so something like this will bypass that particular error message while allowing an error message for any other problem.

Your Sub
on error goto err
DoCmd.OutputTo acQuery, "YourQuery"

'this portion must be positioned immediately before the end sub
exit sub
err:
if err.number=2501 then
exit sub
else
msgbox err.number & ": " & err.description
end if
end sub
 
That works a treat, thanks alot!
 
charityg said:
'this portion must be positioned immediately before the end sub
exit sub
err:
if err.number=2501 then
exit sub
else
msgbox err.number & ": " & err.description
end if
end sub

Or, in one line: ;)

Code:
Err:
    If Err.Number <> 2501 Then MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
End Sub
 

Users who are viewing this thread

Back
Top Bottom