Help Please : De Bug Run Time Error Message Box A2002

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Is there anyway to suppress this message box from opening
and instead
to code the command button to exit the form in the event
of an error ?

Thank you for any assistance

Mike
 
Here is one approach:

Sub cmdButtonX_Click()
On Error GoTo ErrHandler

' Your code here

ExitHere:
Exit Sub 'NOTE: this line is crucial. If omitted ErrHandler code
will ALWAYS run. and run. and run...
ErrHandler:
Select Case Err.Number
' Insert additional cases with specific error numbers if you want to
handle them differently than the default "Case Else".
Case Else
' MsgBox "Your own (optional) custom Error Message", vbOKOnly +
vbCritical, "Error"
DoCmd.Close acForm, Me.Name, acSaveNo
GoTo ExitHere 'good coding requires a *single* exit
point. Go to it.
End Select
End Sub

--

HTH,
George Nicholson

Remove 'Junk' from return address.
 
Back
Top