Hello, I am trying to create a save button and a close button using vbyesnocancel that will work. I created a save button using the wizard in access 2007, which just uses a Macro in the on click event. I've also tried different code in the before update of the form which doesn't work. (Ie. if "No" is clicked the record is still saved or if the form is closed it still saves the record)
I got rid of the before update event in the form and now just concentrating on the buttons, this is what I have so far:
However, it still saves the record when exiting out of the form. Also the close button prompts me to confirm deletion of a record when I select "No."
Any suggestions would be greatly appreciated!
Thanks!
I got rid of the before update event in the form and now just concentrating on the buttons, this is what I have so far:
Code:
Private Sub CommandClose_Click()
'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
MsgBox "Record has been saved"
DoCmd.RunCommand acCmdClose
Else
DoCmd.RunCommand acCmdUndo
DoCmd.RunCommand acCmdClose
End If
End Sub
Private Sub CommandSave_Click()
'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNoCancel, "Changes Made...") = vbYes Then
DoCmd.Save
MsgBox "Record has been saved"
DoCmd.GoToRecord , , acNewRec
Else
Cancel = True
End If
End Sub
However, it still saves the record when exiting out of the form. Also the close button prompts me to confirm deletion of a record when I select "No."
Any suggestions would be greatly appreciated!
Thanks!