VBA Time

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?
 
F

fredg

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.
 
T

TEB2

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.
 
M

Michel Walsh

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
 

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