Msg box to appear before deleting a record

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
 
W

Wayne-I-M

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
 
M

Maurice

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
 
S

smason

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
 
S

smason

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
 
S

smason

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
 
W

Wayne-I-M

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)
 
Top