Timer in form

  • Thread starter bg-consult as, Leif Hauge
  • Start date
B

bg-consult as, Leif Hauge

Can anyone help me with this ?

I want to open a form, input data and press "save" to add the data into a
table. One of the variables on the form should be number of minutes from I
opened the form until I press save. Is there a built-in function that start
a timer and stop a timer, where the output can be saved into a field ?

Any quick input is greatly appreciated.

Regards
Leif Hauge
 
G

Graham R Seach

Leif,

Add the following to the form's Declarations section:
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private lTimeIn As Long

Put the following code in your Save button's Click event:
Private Sub cmdSave_Click()
MsgBox timeGetTime - lTimeIn & " milliseconds"
End Sub

I think you'd be better served to put the following code in the form's
Current event, rather than it's Open event.
Private Sub Form_Open(Cancel As Integer)
lTimeIn = timeGetTime
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
B

Brendan Reynolds

The following assumes that your form is a bound form - it would need some
modification if this is an unbound form. After I'd written this, I re-read
your original message, and noticed that you wanted to count from the opening
of the form rather than the start of adding a new record. In that case, just
move the code from the Form_BeforeInsert event procedure into the Form_Open
event procedure instead.

Option Compare Database
Option Explicit

Private mlngTimer As Long

Private Sub Form_AfterUpdate()
'stop counting
mlngTimer = 0
Me.TimerInterval = 0
End Sub

Private Sub Form_BeforeInsert(Cancel As Integer)
'start counting
mlngTimer = 0
'count minutes
Me.TimerInterval = 60000
'uncomment line below to count seconds for testing
'Me.TimerInterval = 1000
End Sub

Private Sub Form_Open(Cancel As Integer)
'don't start counting until record inserted
Me.TimerInterval = 0
End Sub

Private Sub Form_Timer()
'count
mlngTimer = mlngTimer + 1
Me.Text0 = mlngTimer
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

Top