John, I'm talking about when the user changes data on the
form. Not the design of the form but the data. I want the
user to have the option of excepting the changes or
canceling out. By default the changes are excepted.
I'll take "exception" to your language - I think you mean "accepted"
here! <g>
You can put some VBA code in the Form's BeforeUpdate event. There's a
thread two messages above this message in my newsreader with exactly
the same question, oddly enough!
Try opening the form in design view, view its Properties, and on the
BeforeUpdate event click the ... icon and select "Code Builder".
Access will give you the Sub and End Sub lines; just add the
following:
Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
iAns = MsgBox("OK to save this record?", vbYesNo)
If iAns = vbNo Then
Cancel = True
Me.Undo ' this will erase the form, leave out if you want
' the user to be able to fix up and resave
End If
End Sub
Do note that in my experience this kind of message box becomes VERY
annoying to users in short order, and they'll just click Yes
automatically so it doesn't provide any benefit!