Save record changes immediately

M

Matt

I was always under the impression that in an Access form, when you edit a
field that the changes you were making on the form were happening to the
table data concurrently. I have a bound form that a user uses to
view/update/delete data from. The changes do not affect the table data until
the user clicks on the pencil icon on the left side of the form. If the user
moves to another field or even a new record, the table data is not changed.
I assumed that as the user was typing in the changes, that the table data was
being changed at the same time. Am I wrong and how should I fix this? I
don't know if it matters, but the database is split with the backend on a
server and the user has a runtime version installed locally. Thanks in
advance. Matt
 
A

Alex White MCDBA MCSE

Hi Matt,

What you are experiencing is by design, updates are NOT happening as you
type or move from field to field, moving from record to record is the point
when the record is written/updated etc. You could write a routine to save
when exiting each field but I would strongly advise against it, the method
that is in use works very well as long as you understand when things are
being written. There are other points when data is written, too many to list
but if you really want to save a record now then

Docmd.RunCommand accmdsaverecord

or when closing a form

docmd.close acform, me.name,acsaveyes
 
V

Van T. Dinh

No. The Form has a CurrentRecord buffer. While you are still editing the
CurrentRecord, all edits are in the buffer until the user explicitly saves
the Record or move to another Record upon which the dirtied Record will be
updated into the Table. Even that, the update may not go straight away to
the Table as it can be held in cache for a short time.

Check the Refresh Interval Property of the database.

In code, you can force the update into the Table using the Idle Method of
the DBEngine object.

Check Access VB Help on the Idle Method.
 
V

Van T. Dinh

Beware that the acSaveYes refers to the *design* of the Form and not the
data.

Data is automatically saved / updated into the Table(s) for bound Forms.
 
M

Matt

I have a routine set up so that if the user presses the escape key it will
open a new record. I did this because I thought that when you move to a new
record it would for sure write the changes to the table. However, when the
user presses the escape key to open a new record and then goes back to the
record, the changes didn't take effect. The following is the code used to
open a new record. Maybe that is the problem. Thanks.

Private Sub Tag_Number_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 27
DoCmd.GoToRecord , , acNewRec
End Select
End Sub
 
M

Mauricio Silva

The ESC Key is used to undo your changes and appear it is happening before
you can move to another record.

My suggestion would be to insert the line below in your code:

Private Sub Tag_Number_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 27
Me.Dirty = False
DoCmd.GoToRecord , , acNewRec
End Select
End Sub

the dirty = false command will save your data before you change to a new
record.

Mauricio Silva
 
M

Matt

Thanks for the idea. However, it didn't work. I wonder if it is because I
am using the ESC key. I wonder if it is removing the changes before it
processes the code. Thanks everyone for your help.
 
Top