Save record using a dialog

  • Thread starter Thread starter hans
  • Start date Start date
H

hans

I do not want Access to save the record. I want the user to answer yes
or no on a dialog asking the user if he/she want to save the record or
changes. How can I do this. I do not know how to write Basic.
 
There are so many ways that a record can be saved, e.g. moving to another
record, pressing Shift+Enter, choose Save Record on the Records menu,
closing the form, closing Access, applying a filter, changing the sort
order, requerying, etc, etc.

The *only* way to catch them all is to use the BeforeUpdate event procedure
of the form, cancel the event, and undo the form if you don't want it saved.

1. Open the form in design view.

2. Open the Properties box (View menu.)
Make sure its Title reads "Form", i.e. you are looking at the properties of
the form, not those of a control or section.

3. On the Events tab of the Properties box, set the form's Before Update
property to:
[Event Procedure]

4. Click the Build button (...) beside this.
Access opens the code window.

5. Enter the 4 lines below inside the event code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Save?", vbOkCancel) = vbCancel Then
Cancel = True
Me.Undo
End If
End Sub
 
Back
Top