You could use the form's Current event to set the value of an unbound (hidden)
text box to a value such as 1. In the Click event of the button, set the
text box value to 2. In the form's Before Update event, check the text box
value before saving the record:
Private Sub Form_Current()
Me.txtCheck = 1
End Sub
Private Sub cmdSave_Click()
Me.txtCheck = 2
Me.Dirty = False ' This saves the record
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.txtCheck = 1 Then
MsgBox "You didn't click the Save button. Changes won't be saved."
Me.Undo
End If
Exit Sub
I wonder why you would want to do it this way, unless there is a need for
something to happen each time the record is changed (print a report, send an
e-mail, or whatever). You may want to give the users a chance to go back and
click the required button rather than simply notifying them that the changes
will be discarded:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.txtCheck = 1 Then
If MsgBox ("Click the button to save the record", vbOkCancel) = vbOK Then
Cancel = True
Me.CommandButtonName.SetFocus
Else
Me.Undo
End If
End If
Exit Sub
Use whatever error message you like, and use vbYesNo (or something else)
instead of vbOKCancel if it makes more sense.