delete record

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
 
D

Dirk Goldgar

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
 

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