Stop Refresh / Stop Requery

pieterw

Registered User.
Local time
Today, 06:10
Joined
Apr 20, 2010
Messages
12
Hi all

i have a simple access form with a kind of a chrono field

(the 'timer function' is inserted in the code)
when the user hits a button, it registers a timestamp and another field starts the count

timestamp is saved in box 'begin'

the other box ('chrono') contains the formula
"now()-[begin] "

a Me.chrono.requery is running so i see the form/chronofield refreshing every second, the count is running

to finalise i need a piece of code to stop requery-ing the chrono somehow

when the user hits the stop button it should 'freeze' the value in the chrono box (this value being only informational display, not to be used for other purposes or not to be saved somewhere)

i would need something like

Private Sub Command10_Click()
Me.chrono.stoprequery-ing
End Sub


(I realise that this is probably not the correct way to work, but i am almost set right now, and if this code qhould exist, i do not have to strat all over again)

every piece of info is welcome!

thanks in advance!
 
The way I would do this is to control it all by code as follows.

When the user clicks the begin button (use the begin button's OnClick event) to set the value of the Begin field:

Private Sub cmdBegin_Click()

blnTimer = True
Me.txtBegin.Value = Now()

End Sub

You will notice that there is a variable in this procedure called blnTimer. This is a public declared variable (can be declared at the top of the form's code module)

Option Compare Database
Option Explicit

Public blnTimer As Boolean

that will be used to control the form's timer, as follows:

Private Sub Form_Timer()

If blnTimer Then
Me.txtDifference = Int((Now() - Me.txtBegin.Value) * 24 * 60 * 60)
End If

End Sub

When the user clicks the Stop button then, the following code is called (use the stop button's OnClick event):

Private Sub cmdStop_Click()

blnTimer = False

End Sub


This then stops the txtDifference field from being updated, even though the form's timer keeps running.
 

Users who are viewing this thread

Back
Top Bottom