Still getting error 2501 on DeleteRecord

B

Baby Face Lee

Hi everyone
I'm sure it's me being dim but I can't see why I'm still getting a 2501
runtime error when the user wishes to cancel a DeleteRecord action.

Here's my code on the BEFOREDELCONFIRM event of the FORM:

Dim intResponse As Integer
intResponse = MsgBox("You are about to delete a Candidate record." _
& vbCrLf & "Any Components recorded for the Candidate will also be
deleted." _
& vbCrLf & vbCrLf & "Click on OK to proceed. This process cannot be
undone." _
& vbCrLf & vbCrLf & "Click on Cancel to exit the deletion process.", _
vbExclamation + vbOKCancel + vbDefaultButton2, "WARNING!!!")
If intResponse = vbCancel Then
Cancel = True
ElseIf intResponse = vbOK Then
Response = acDataErrContinue
End If

Here's my code in the ONCLICK event of the command button CmdDelete:
Private Sub cmdDelete_Click()
On Error GoTo Handle_Err

If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If

Handle_Exit:
Exit Sub
Handle_Err:
Select Case Err.Number
Case 2501
' the RunCommand action was cancelled.
Resume Handle_Exit
Case Else
MsgBox Err.Number & ": " & Err.Description _
& vbCr & "Please contact Linda Lawson.", _
"Unknown error"
Resume Handle_Exit
End Select
End Sub

How can I stop this error appearing?

Thanks for any help you can give.

Lee
 
A

Allen Browne

You have handled error 2501 in cmdDelete_Click, so the error must be from
another event.

When the error occurs, the built-in error message has buttons for Debug and
End. Choose Debug, and you can see the event that is generating the error
(e.g. Form_BeforeDelConfirm, or Form_Current). Add the same kind of
error-handling to that event also.

This is usually only a problem with Access 2002 Service Pack 3.
 
B

Baby Face Lee

Just wanted to reply to say thanks to Allen for his response but I've found
out (at last) what the problem was - having also experienced peculiar
'errors' within Trevor Best's domain aggregate functions (tLookup etc...) :

Within the Visual Basic window, click on Tools/Options and then the General
tab and under Error Trapping, set the option to 'Break on Unhandled Errors'.
This is the default setting but somehow (and I haven't a clue how!) it had
been set to 'Break on all errors'.

Anyway, thought this might help some other poor soul scratching around for a
similar solution.

Regards,

Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top