Forms - Autosave a Record

  • Thread starter Thread starter The Boondock Saint
  • Start date Start date
T

The Boondock Saint

Howdy Everyone

Im just wondering , Is there a way you can autosave a record that you have
open every say 10secs?

Access 2000

Cheers Saint
 
I'm not sure why you need to do that, because when you exit the record it
will be automatically saved.
But you can use the form Ontimer with the Timer Interval to set the auto
saved every 10 seconds with this line

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
 
Im already using the ontimer in the form... which has the time a clock
counter .... thats why i need it to autosave ...

how can i make it so it autosaves every 10secs for example... i tried that
code but it was saving every sec..
 
The said:
Im already using the ontimer in the form... which has the time a
clock counter .... thats why i need it to autosave ...

how can i make it so it autosaves every 10secs for example... i tried
that code but it was saving every sec..

You need a numeric variable declared at the top of your module (not in the timer
code). In the timer code add one to this variable each time and then use an
If-Block to test the variable. If the variable is equal to 10 then save the
record and reset the variable to zero. If it is less than 10 then do nothing.
 
This example shows how you can use the Timer event to perform two operations
at different intervals ...

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()

Static Counter As Long

Me.lblClock.Caption = Now()
Counter = Counter + 1
If Counter Mod 10 = 0 Then
Debug.Print "Saving at: " & Now()
Me.Dirty = False
End If

End Sub
 
I am wondering the policy / decision to save the Record every 10 secs.
Normally, a Record should only be save when there is some new / updated data
to be saved. I have done numerous databases and yet to come to a situation
where a Record needs to be saved every X seconds.

That's said, it seems that you already used the Form_Timer Event to update
the "clock" on the Form every second. In this case, leave the TimerInterval
at 1000 msecs but add a static count variable and only issue a save
statement every time the count reach 10.

The code should be something like:

****untested****
Private Sub Form_Timer()
Static intCount As Integer

' Your current code here
intCount = intCount + 1
If intCount = 10 then
DoCmd.RunCommand acCmdSaveRecord
intCount = 0
End If
End Sub
********
 

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

Similar Threads


Back
Top