(Q) How can I control when a record is saved in a form?
(A) Use the form's BeforeUpdate event to run code each time Access
tries to save a record. This way, if the user doesn't want to save a record,
you can issue an Undo command instead of saving the record.
Note: This will generate a Message Box asking for confirmation each time a
changed record is saved. I leave it on whoever is going to follow this method to
determine how to refine this per user preference. (Hint: Try a Checkbox.)
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "@Do you wish to save the changes?"
strMsg = strMsg & "@Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub
|