Cancelling vb action

  • Thread starter Thread starter AWM
  • Start date Start date
A

AWM

I have created the following code that is executed at the OnClick event
of a command button:

--------------------
Private Sub Command56_Click()

DoCmd.OutputTo acOutputQuery, "qry_CADDWGLog_Export", acFormatXLS

Exit_Command56_Click:
Exit Sub

Err_Command56_Click:
MsgBox Err.Description
Resume Exit_Command56_Click

End Sub

--------------------
The code works great except if the operator cancels the download
OutputTo action. When the action is cancelled, a dialog box appears
stating...

Run-time error 2501

The OutputTo action was cancelled.

<End> <Debug> <Help>

I want to avoid the opportunity for the operator to click <debug> and
thereby enter the VB environment.

Any recommendations? Thanks. Art
 
You need to insert an error handler statement:


Private Sub Command56_Click()
On Error GoTo Err_Command56_Click
DoCmd.OutputTo acOutputQuery, "qry_CADDWGLog_Export", acFormatXLS

Exit_Command56_Click:
Exit Sub

Err_Command56_Click:
MsgBox Err.Description
Resume Exit_Command56_Click

End Sub
 
You can disable the ability for application users to debug by changing some
of the startup options.

Tools>Startup>...

Look for 'Use Special Access Keys' and disable--that should prevent users
from debugging. Take a look around at some of the startup options while you
are there.


Todd
 
Back
Top