VBA Time

  • Thread starter Thread starter TEB2
  • Start date Start date
T

TEB2

I have a form that has a very simple progress bar. How do I add a timer that
shows the elapsed time aslo?
 
I have a form that has a very simple progress bar. How do I add a timer that
shows the elapsed time aslo?

Add an unbound control to the form.
Name it "txtElapsedTime"
Leve gthe control's Format property blank.

Then set the Form's Timer Interval to 1000

Here is the code to make it work:

Option Compare Database
Option Explicit
Dim TheClock As Date

Private Sub Form_Load()
TheClock = Time()
End Sub

Private Sub Form_Timer()
txtTimeElapsed = DateDiff("S", TheClock, Time()) \ 60 & ":" &
Format(DateDiff("s", TheClock, Time()) Mod 60, "00")

End Sub

Whatch for word wrap above.
The above will count the minutes and seconds since the loading of the
form, i.e. 0:05, 0:16, 1:56, etc.
 
Will the timer stop when my Sub is completed?

fredg said:
Add an unbound control to the form.
Name it "txtElapsedTime"
Leve gthe control's Format property blank.

Then set the Form's Timer Interval to 1000

Here is the code to make it work:

Option Compare Database
Option Explicit
Dim TheClock As Date

Private Sub Form_Load()
TheClock = Time()
End Sub

Private Sub Form_Timer()
txtTimeElapsed = DateDiff("S", TheClock, Time()) \ 60 & ":" &
Format(DateDiff("s", TheClock, Time()) Mod 60, "00")

End Sub

Whatch for word wrap above.
The above will count the minutes and seconds since the loading of the
form, i.e. 0:05, 0:16, 1:56, etc.
 
A form's timer stops if you set its timer interval to zero, or if the form
owning the timer get closed. It is the form who owns the timer, not a
subroutine.

The timer does NOT stop if another form is open into a dialog mode.

The timer interval is appreciative: if other urgent job is to be performed
by the computer, the timer may 'miss' many firing cases.




Vanderghast, Access MVP
 
Back
Top