Delete record

G

Guest

I am using the command button wizard to generate delete record code. When the user deletes a record a message box comes up saying how many records are going to be deleted and click yes or no. Is there a way to control this message box? I placed the generated code below? What calls the message box? Is there a way I can trap the key stroke so If yes is clicked I can also close the form and if No is clicked then I can do another function? Thanks for the help

Private Sub cmdDelete_Click(
On Error GoTo Err_cmdDelete_Clic

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer7
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer7

Exit_cmdDelete_Click
Exit Su

Err_cmdDelete_Click
MsgBox Err.Descriptio
Resume Exit_cmdDelete_Clic

End Sub
 
D

Dirk Goldgar

brian said:
I am using the command button wizard to generate delete record code.
When the user deletes a record a message box comes up saying how many
records are going to be deleted and click yes or no. Is there a way
to control this message box? I placed the generated code below?
What calls the message box? Is there a way I can trap the key stroke
so If yes is clicked I can also close the form and if No is clicked
then I can do another function? Thanks for the help!

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub

The warning is controlled by the option setting Tools -> Options... ->
Edit/Find -> Confirm, Record changes. You can turn it off and on
temporarily using the DoCmd.SetWarnings method. You can trap the user's
canceling of the deletion if you rewrite the code like this:

'---- start of revised code -----
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

RunCommand acCmdDeleteRecord

Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
If Err.Number = 2501 Then
' The user cancelled the delete.
' ... run some code from here if you want ...
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdDelete_Click
End If

End Sub
'---- end of revised code -----
 

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