Weird message box question

V

vainglory

See code below. I figured I'd get the message box asking me to delete
the record twice if I hit errors 3022 or 3058. But I don't. I just
get it once. How is this possible?

Thanks in advance,
Paolo


Private Sub Command2_Click()
On Error GoTo ErrHandler
'Delete Record on form
Delete:
If MsgBox("Are you sure you want to delete the record?", _
vbQuestion + vbYesNo, "Delete?") = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
End If
Command2_Click_Exit:
Exit Sub
ErrHandler:
Select Case Err.Number
Case 3200
MsgBox "Location is referenced in another form!",
vbCritical, _
"Referential Integrity Error"
Me.Undo
Case 3022, 3058
Me.Undo
If Not Me.NewRecord Then
GoTo Delete
End If
Case Else
MsgBox "Error in Command2_Click()." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf &
Err.Description
End Select
Err.Clear
Resume Command2_Click_Exit
End Sub
 
M

Marshall Barton

vainglory said:
See code below. I figured I'd get the message box asking me to delete
the record twice if I hit errors 3022 or 3058. But I don't. I just
get it once. How is this possible?


Private Sub Command2_Click()
On Error GoTo ErrHandler
'Delete Record on form
Delete:
If MsgBox("Are you sure you want to delete the record?", _
vbQuestion + vbYesNo, "Delete?") = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
End If
Command2_Click_Exit:
Exit Sub
ErrHandler:
Select Case Err.Number
Case 3200
MsgBox "Location is referenced in another form!",
vbCritical, _
"Referential Integrity Error"
Me.Undo
Case 3022, 3058
Me.Undo
If Not Me.NewRecord Then
GoTo Delete
End If
Case Else
MsgBox "Error in Command2_Click()." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf &
Err.Description
End Select
Err.Clear
Resume Command2_Click_Exit
End Sub


I don't know, but the one thing that jumps out of your code
is that you need to use Resume Delete instead of GoTo
Delete.
 

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

Top