error handling

  • Thread starter Thread starter Bill H.
  • Start date Start date
B

Bill H.

Have this code fragment.

When I click on the delete command button when on a new record, instead of
the error being handled by Err-DelRec_Click, I just get the access error
window referencing error code 2046.

How do I get it to go to MY handler?

Thx.

Private Sub DelRec_Click()
On Error GoTo Err_DelRec_Click
DoCmd.RunCommand acCmdDeleteRecord

Exit_DelRec_Click:
Exit Sub

Err_DelRec_Click:
Select Case Err.Number
Case 3200
Beep
Case 2046 'tried to delete on new record
Resume next
Exit Sub
End Select
msgbox Err.Description
Resume Exit_DelRec_Click
End Sub
 
You might need to test whether DelRec_Click is firing at all. There may be
another data error occurring. For example, if the cursor is in a partly
filled in date, and you attempt to click the button, Access won't let the
focus out of the active text box until the date is completed, so the
button's Click event is not called at all yet.

If it's not that issue, consider dealing with the obvious possibilities in
your code like this:

If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
DoCmd.RunCommand acCmdDeleteRecord
End if

Keep your basic error handling, of course.
 
Back
Top