Saving a form

J

Jerry

Could someone please tell me the code for saving a form
prior to exiting. Where the form would return to its
original state without saving. I would like a msgbox to
allow the user to save or cancel the changes.

Thanks
Jerry
 
J

John Vinson

Could someone please tell me the code for saving a form
prior to exiting. Where the form would return to its
original state without saving. I would like a msgbox to
allow the user to save or cancel the changes.

Are you talking about changes to the design of the Form itself, or to
the data displayed on the form?
 
J

Jerry

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.

Thanks
Jerry
 
J

John Vinson

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top