I have a form that opens and takes data from a table; and puts it in text boxes. There is button on this form, named "CustomerInfoBackBtn".
The code I have inside of it that doesn't work (well, it might... just Access automatically saves the data anyways when I edit the text boxes) is this:
Private Sub CustomerInfoBackBtn_Click()
Dim LResponse As Integer
LResponse = MsgBox("Would you like to save?", vbYesNo, "Save?")
If LResponse = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
DoCmd.OpenForm "CustomerListF"
Else
DoCmd.Close
DoCmd.OpenForm "CustomerListF"
End If
End Sub
How do I make it pop up the msgbox asking them if they would like to save, and if they push yes it saves, then refreshes the subform and THEN opens the previous form (CustomerListF) and if they push no, it doesn't save, reverts information to what it was before, and opens up the previous form? I think all I really need is a way to stop access from automatically saving the data changes, but I am not sure.
Edit for answer:
Code in button that pulls up that error:
Dim TempSaveRecord As Boolean
Private Sub CustomerNotesBackBtn_Click()
If MsgBox("Do you want to save your changes?", vbInformation + vbYesNo, [Warning! Some data may be lost.]) = vbNo Then
TempSaveRecord = False
Else
TempSaveRecord = True
End If
DoCmd.Close
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If (TempSaveRecord) Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub