Save a record by clicking Save

  • Thread starter Thread starter Pontus
  • Start date Start date
P

Pontus

Access automatically saves changes when you move off each
record, I want to save information only when I click on a
save button in the form. Is this possible to do? Do you
have to use VBA for this?

/Pontus
 
The only way to save information ONLY when you click a button is to use
unbound forms/controls and perform the database inserts/updates/deletes
yourself (which kind of defeats the purpose). If you want to force a save,
you can add code like this to a button on your form:

Sub btnClick_Click()
If Me.Dirty Then
Me.Dirty = False
End If
End Sub
 
I am working on the same type of problem. I am finding
that to do it right it is quite involved but you can use
a cancel and save button to do this. Create an 'undo'
button (it can be created by the cmd button wizard). Use
the Dirty property of the form to monitor if the record
has changed. If it has, set the enabled property of the
save and cancel buttons to true. In the click event for
the save and cancel buttons, set their enabled property
to false. Unfortunately, this still does not keep the
user from moving to another record using the navigation
buttons or the keyboard. What I am trying to do with my
program is to filter the form by the current selection so
that the only record accessible by the user is the
current one until they save or cancel changes. Obviously
I am using VBA.

hth
 
I am working on the same type of problem. I am finding
that to do it right it is quite involved but you can use
a cancel and save button to do this.

Your technique is a good one; but you can add some extra protection.

Put a global Boolean variable bOKToClose in your form's module by
putting

Public bOkToClose As Boolean

at the top of the module, before any Subs. In the Form's Current event
set it to False; set it to True in the Save button code; and check its
value in the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not bOKToClose Then
MsgBox "Please use the buttons", vbOKOnly
Cancel = True
End If
End Sub
 
Back
Top