junmart
10-02-2001, 11:46 AM
how do i make my data entry form close without saving whatever i typed in it. i have a save button and a "close without saving" button. the second button seems not to work. the data i didnt want to save is in the table when i close the form by clicking on "close without saving" button. any ideas from anyone?
jwindon
10-02-2001, 02:35 PM
Put this code on your second button.
Private Sub Command4_Click()
DoCmd.SetWarnings (False)
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings (True)
DoCmd.Close acForm, "Form1", acSaveNo
End Sub
HTH!
[This message has been edited by jwindon (edited 10-02-2001).]
Me.Undo is much easier and more efficient.
Pat Hartman
10-02-2001, 02:57 PM
You need to define a public variable for the form, set this variable in three places and check it in one. This method will handle closing the form by any method including exiting the database as well as using the record navigation buttons.
OnCurrent event of the form -
MyVar = "anything"
Click event of the Save button =
MyVar = "save"
Click event of the Cancel button -
MyVar = "cancel"
BeforeUpdate event of the form =
Select Case MyVar
Case "save"
Case "cancel"
Cancel = True
Case Else
If msgbox("Do you want to save record?", vbYesNo) = vbNo
Cancel = True
End If
End Select
I don't know what jwindon's DoMenuItem Methods are supposed to do because I don't have Access95 loaded but I do know the the acSaveNo in the Close Method refers to the active form NOT the current record.
jwindon
10-02-2001, 03:48 PM
Pat:
If you look at the original question, he had the button read "Close without saving". I took that to mean close the form WITHOUT saving the form.
I agree with the UNDO. I wasn't sure if that would just UNDO one step in the data entry or not. Thanks for the new info Rich.
[This message has been edited by jwindon (edited 10-02-2001).]