I am using the following command to delete records.
DoCmd.RunCommand acCmdDeleteRecord which is fine if the user presses OK but if the user presses No it just crashes. How do I code this with my own error messages. Below is what I have so far but that deletes whether you press or no as the delete is already done.
Dim Msg, Style, Title, Response
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
Msg = "You are about to delete a line. Do you really want to do this?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Warning" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
Else ' User chose No.
DoCmd.Hourglass False
Exit Sub
End If
DoCmd.RunCommand acCmdDeleteRecord which is fine if the user presses OK but if the user presses No it just crashes. How do I code this with my own error messages. Below is what I have so far but that deletes whether you press or no as the delete is already done.
Dim Msg, Style, Title, Response
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
Msg = "You are about to delete a line. Do you really want to do this?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Warning" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
Else ' User chose No.
DoCmd.Hourglass False
Exit Sub
End If