Timer

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi all,

I would like to put a timer object on a form with start and stop buttons.
so I can see how much time has elapsed.

Any ideas?

TIA,

Tom
 
Hi all,

I would like to put a timer object on a form with start and stop buttons.
so I can see how much time has elapsed.

Any ideas?

TIA,

Tom

If that's all you wish to do you don't need to use the timer. Nor do
you need 2 command buttons.

Add a text control. Name this one "StartTime"
Add another control. Name this one "EndTime"
Add another control. Name this "Elapsed"

Add one command button. Caption = "Start"

Code it's click event:

If Me!CommandName.Caption = "Start" Then
Me![StartTime] = ""
Me![EndTime] = ""
StartTime = Time
Me![CommandName].Caption = "Stop"
Else
[EndTime] = Time
[Elapsed] = DateDiff("s", [StartTime], [EndTime])
Me![CommandName].Caption = "Start"
End If


The difference, in seconds, between the StartTime and EndTime will
display in the Elapsed control.
 
Thanks Fred, this is great,
How do I format it to hours, minutes and seconds?

I tried to replace the " s" with hh:nn:ss but it didnt work.

TIA,

Tom
fredg said:
Hi all,

I would like to put a timer object on a form with start and stop buttons.
so I can see how much time has elapsed.

Any ideas?

TIA,

Tom

If that's all you wish to do you don't need to use the timer. Nor do
you need 2 command buttons.

Add a text control. Name this one "StartTime"
Add another control. Name this one "EndTime"
Add another control. Name this "Elapsed"

Add one command button. Caption = "Start"

Code it's click event:

If Me!CommandName.Caption = "Start" Then
Me![StartTime] = ""
Me![EndTime] = ""
StartTime = Time
Me![CommandName].Caption = "Stop"
Else
[EndTime] = Time
[Elapsed] = DateDiff("s", [StartTime], [EndTime])
Me![CommandName].Caption = "Start"
End If


The difference, in seconds, between the StartTime and EndTime will
display in the Elapsed control.
 
Thanks Fred, this is great,
How do I format it to hours, minutes and seconds?

I tried to replace the " s" with hh:nn:ss but it didnt work.

TIA,

Tom
fredg said:
Hi all,

I would like to put a timer object on a form with start and stop buttons.
so I can see how much time has elapsed.

Any ideas?

TIA,

Tom

If that's all you wish to do you don't need to use the timer. Nor do
you need 2 command buttons.

Add a text control. Name this one "StartTime"
Add another control. Name this one "EndTime"
Add another control. Name this "Elapsed"

Add one command button. Caption = "Start"

Code it's click event:

If Me!CommandName.Caption = "Start" Then
Me![StartTime] = ""
Me![EndTime] = ""
StartTime = Time
Me![CommandName].Caption = "Stop"
Else
[EndTime] = Time
[Elapsed] = DateDiff("s", [StartTime], [EndTime])
Me![CommandName].Caption = "Start"
End If


The difference, in seconds, between the StartTime and EndTime will
display in the Elapsed control.


Your Elapsed time is a Number value, not a Time value.

Divide seconds by 3600 to get hours.
Divide seconds by 60 to get minutes.
Look up the Mod operator in VBA help.

Change your code to:
*** Note the use of the backslash \ as integer divider below ***

If Me.CommandName.Caption = "Start Time" Then
Me![StartTime] = ""
Me![EndTime] = ""
Me![Elapsed] = ""
StartTime = Time
Me![CommandName].Caption = "Stop Time"
Else
[EndTime] = Time
[Elapsed] = DateDiff("s", [StartTime], [EndTime])
[Elapsed] = [Elapsed] \ 3600 & "h" & ([Elapsed] Mod 3600) \ 60 &
"m" & (([Elapsed] Mod 3600) Mod 3600) Mod 60 & "s"

Me![CommandName].Caption = "Start Time"
End If
 
Thank you so much.
fredg said:
Thanks Fred, this is great,
How do I format it to hours, minutes and seconds?

I tried to replace the " s" with hh:nn:ss but it didnt work.

TIA,

Tom
fredg said:
On Mon, 5 Nov 2007 10:55:15 -0500, Tom wrote:

Hi all,

I would like to put a timer object on a form with start and stop
buttons.
so I can see how much time has elapsed.

Any ideas?

TIA,

Tom

If that's all you wish to do you don't need to use the timer. Nor do
you need 2 command buttons.

Add a text control. Name this one "StartTime"
Add another control. Name this one "EndTime"
Add another control. Name this "Elapsed"

Add one command button. Caption = "Start"

Code it's click event:

If Me!CommandName.Caption = "Start" Then
Me![StartTime] = ""
Me![EndTime] = ""
StartTime = Time
Me![CommandName].Caption = "Stop"
Else
[EndTime] = Time
[Elapsed] = DateDiff("s", [StartTime], [EndTime])
Me![CommandName].Caption = "Start"
End If


The difference, in seconds, between the StartTime and EndTime will
display in the Elapsed control.


Your Elapsed time is a Number value, not a Time value.

Divide seconds by 3600 to get hours.
Divide seconds by 60 to get minutes.
Look up the Mod operator in VBA help.

Change your code to:
*** Note the use of the backslash \ as integer divider below ***

If Me.CommandName.Caption = "Start Time" Then
Me![StartTime] = ""
Me![EndTime] = ""
Me![Elapsed] = ""
StartTime = Time
Me![CommandName].Caption = "Stop Time"
Else
[EndTime] = Time
[Elapsed] = DateDiff("s", [StartTime], [EndTime])
[Elapsed] = [Elapsed] \ 3600 & "h" & ([Elapsed] Mod 3600) \ 60 &
"m" & (([Elapsed] Mod 3600) Mod 3600) Mod 60 & "s"

Me![CommandName].Caption = "Start Time"
End If
 
Back
Top