Hello Andrea,
You should be able to find all the info you need in the Access' buil-in
help, but there is also lots of info on the Web.
Below is some sample code from a Web site called The Access Web,
http://www.mvps.org/access/ to do just this.
To create the BeforeUpdate sub you open the form in design mode, display the
Properties pane (There is a button on the toolbar).
Then scroll down in the window untill you see the property Before Update.
Then click in the right hand end of the empty box next to Before Update and
select [Event Procedure]. Then click on the little button to the rigth of
the box and the Visual Basic editor window opens with the first and the last
line of the sub already entered.
Then you select all but the first and thelast line of the code below, hit
the save button, and you are all set.
BTW, Visual Basic is easy to learn and well wort the effort. Macros should
be avoided if at all possible, Macros can do most of the basic operations
you can do with code but they are confusing and can not be debugged easily.
In VB you can step through your code line by line and see excatly what
happens, you can look at the values of all the variables.
Ragnar
----------------------------------------------------------------------------
--------------
(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.)
'****************** Code Start ******************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 'do
nothing Else DoCmd.RunCommand acCmdUndo 'For Access
95, use DoMenuItem instead 'DoCmd.DoMenuItem acFormBar, acEditMenu,
acUndo, , acMenuVer70 End IfEnd Sub'****************** Code End
******************