Msg box to appear before deleting a record

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

hello

i have a form which i have added a delete button to!

however i want to have a msg box apear prior to the record being deleted
asking 'do you want to delete record' with a yes / no buttons and if the
answer is no then its not deleted if yes then is is deleted!

Please help !!! as its driving me made
 
Hi Steve

Try this (change the messages to what you want) take off the "else" if you
don't want it.


Private Sub Button_Click()
DoCmd.SetWarnings False
If MsgBox("Do you really want to delete this record?", vbQuestion + vbYesNo)
= vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
MsgBox "OK it's not been cancelled"
End If
DoCmd.SetWarnings True
End Sub
 
Try somehting like this:

private sub button_click
dim iChoice as Integer

iChoice= msgbox("Do you want to delete?", vbYesNo)

Select Case iChoice
Case=6
DoCmd.DoMenuItem acFormbar, acEditMenu, 8, ,acMenuVer70
DoCmd.DoMenuItem acFormbar, acEditMenu, 8, ,acMenuVer70
Case = 7
'-> do what you want to do in case of No...
End Select

end sub


The docmd. option is a wizard generated piece of code while creating a
deletebutton with the wizard.

hth
 
Hello

thanks for the reply
how ever i am getting an error on this line
If MsgBox("Do you really want to delete this record?", vbQuestion + vbYesNo)
= vbYes Then

is is red!

any ideas
 
Hello Maurice

thanks for the reply

however when i tried this the message box came up but it didn't delete the
record!
also what could i do if the answer is no how would i just leave the record
there!

any ideas !!!

thanks in advance
 
sorry it worked perfectly
i am stupid!

Wayne-I-M said:
Hi Steve

Try this (change the messages to what you want) take off the "else" if you
don't want it.


Private Sub Button_Click()
DoCmd.SetWarnings False
If MsgBox("Do you really want to delete this record?", vbQuestion + vbYesNo)
= vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
MsgBox "OK it's not been cancelled"
End If
DoCmd.SetWarnings True
End Sub
 
It's on one line - this forum text box sometimes shortens lines - make sure
that

If MsgBox("Do you really want to delete this record?", vbQuestion + vbYesNo)
= vbYes Then

(Mind you - you may say "that" one one line as well - oh well)
 

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

Back
Top