PDA

View Full Version : Auto Save



Movian
03-20-2009, 08:55 AM
A while ago i made a post about automaticly saving information from the form to the table.

i did get a solution but there were some downsides to my aproach in that it would cause random focus changes.

i am now review the code and have opted to take the following aproach

Dim mydb As DAO.Database
Dim myrs As DAO.Recordset
Set mydb = CurrentDb
Set myrs = mydb.OpenRecordset("Settings")
If myrs.Fields("AutoSave") = True Then
Me.Dirty = False
Forms("frmMain").Controls("fsubmodule").Form.isdirty
End If
myrs.Close
Set myrs = Nothing
mydb.Close
Set mydb = Nothing
The problem is, that when the event ocurs and say a person is typing in a field. it will highlight all the text in the field so when they press the next key it deletes the information.

What would i need to do to A) Ensure that if we enter a new record then without closing the form. go to another machine we will be able to see that record. and B) ensure that the saving proceudre does not affect data entry at the same time it is being saved.


any help would be helpfull on this as i am on a time limit and i have spent hours on this today allready :bug:

EDIT~ infact another interesting thing that ocurs is that sometimes when the autosave procuedre runs while someone is tuping text. The text will disapear untill you set focus on another control.

OBP
03-20-2009, 09:01 AM
As I said I would use a Recordset to save the current record directly to the table, assuming that it is a new record you would need to use something like this
With rstable
.AddNew
!date = Me.Report_Date
!team = team
![Idle Code] = Code
![Agent ID] = Val(Agent)
!Agent = Name
!Duration = Timed
![Time In Code] = Val(tic)
.Update
.Bookmark = .LastModified
End With

Where rstable is the recordset opened on the table.

Movian
03-20-2009, 09:31 AM
ok and what about for consecutive saves (every 20 to 30 seconds)

OBP
03-20-2009, 09:36 AM
When it has been saved once you then Edit the data not Addnew, like this

With rs
.Edit
!InStock = 0
!OutInField = -1
.Update
.Bookmark = .LastModified
End With

But wouldn't it be better to only update "On Change" of data?

Movian
03-20-2009, 09:40 AM
so you think i should put code in each on change event to call the save function as you described it ?

that might be a better way of doing it rather than trying to force a save with timer....

OBP
03-20-2009, 09:46 AM
Well I just thought that there is not much point Writing to the table if nothing has changed, especially if you more than one person in the table at the same time.
You could use the On dirty or before update of the form, or the after update events of the fields.

Movian
03-20-2009, 10:13 AM
i think the on on change event would be over kill as that will save after each keypress. I will try and put the code in on the after update event of each field. *grabs the extensability refrence*