delete record

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

I would like to include an "IF" statement on a command
button so the user will be prompted if they click the
button to delete the record. I would like to ask "Are you
sure you want to delete this record?" with a yes/no. If
no then do nothing. Help!

Don
 
Don said:
I would like to include an "IF" statement on a command
button so the user will be prompted if they click the
button to delete the record. I would like to ask "Are you
sure you want to delete this record?" with a yes/no. If
no then do nothing. Help!

You would use the MsgBox() function for this. Something like

If MsgBox( _
"Are you sure you want to delete this record?", _
vbYesNo, _
"Confirm Deletion") _
= vbYes _
Then
RunCommand acCmdDeleteRecord
End If

Note that, as it stands, Access will probably also ask for confirmation
of the deletion (unless the default option has been changed). If you
want to suppress Access's message, you can use this:

If MsgBox( _
"Are you sure you want to delete this record?", _
vbYesNo, _
"Confirm Deletion") _
= vbYes _
Then
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If
 
Back
Top