A friend of mine sent be the following code that works with a form only after the user clicks the start button, stops when they click the stop button and resets to 0 when they click the rest button.
.............................................
Option Compare Database
Option Explicit
Dim TotalElapsedMilliSec As Long
Dim StartTickCount As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub btnStartStop_Click()
If Me.TimerInterval = 0 Then
StartTickCount = GetTickCount()
Me.TimerInterval = 15
Me!btnStartStop.Caption = "Stop"
Me!btnReset.Enabled = False
Else
TotalElapsedMilliSec = TotalElapsedMilliSec + (GetTickCount() - StartTickCount)
Me.TimerInterval = 0
Me!btnStartStop.Caption = "Start"
Me!btnReset.Enabled = True
End If
End Sub
Private Sub Form_Timer()
Dim Hours As String
Dim Minutes As String
Dim Seconds As String
Dim MilliSec As String
Dim Msg As String
Dim ElapsedMilliSec As Long
ElapsedMilliSec = (GetTickCount() - StartTickCount) + TotalElapsedMilliSec
Hours = Format((ElapsedMilliSec \ 3600000), "00")
Minutes = Format((ElapsedMilliSec \ 60000) Mod 60, "00")
Seconds = Format((ElapsedMilliSec \ 1000) Mod 60, "00")
MilliSec = Format((ElapsedMilliSec Mod 1000) \ 10, "00")
Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec
End Sub
Private Sub btnReset_Click()
TotalElapsedMilliSec = 0
Me!ElapsedTime = "00:00:00:00"
End Sub
..................................................
I need to have the stopwatch run continually when the form it’s embedded in opens for the users to view the continuous elapsed time a form/process was open. Then after the form is closed I need it to stop and rest to 0.
Can this be accomplished or is there and easier way?
.............................................
Option Compare Database
Option Explicit
Dim TotalElapsedMilliSec As Long
Dim StartTickCount As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub btnStartStop_Click()
If Me.TimerInterval = 0 Then
StartTickCount = GetTickCount()
Me.TimerInterval = 15
Me!btnStartStop.Caption = "Stop"
Me!btnReset.Enabled = False
Else
TotalElapsedMilliSec = TotalElapsedMilliSec + (GetTickCount() - StartTickCount)
Me.TimerInterval = 0
Me!btnStartStop.Caption = "Start"
Me!btnReset.Enabled = True
End If
End Sub
Private Sub Form_Timer()
Dim Hours As String
Dim Minutes As String
Dim Seconds As String
Dim MilliSec As String
Dim Msg As String
Dim ElapsedMilliSec As Long
ElapsedMilliSec = (GetTickCount() - StartTickCount) + TotalElapsedMilliSec
Hours = Format((ElapsedMilliSec \ 3600000), "00")
Minutes = Format((ElapsedMilliSec \ 60000) Mod 60, "00")
Seconds = Format((ElapsedMilliSec \ 1000) Mod 60, "00")
MilliSec = Format((ElapsedMilliSec Mod 1000) \ 10, "00")
Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec
End Sub
Private Sub btnReset_Click()
TotalElapsedMilliSec = 0
Me!ElapsedTime = "00:00:00:00"
End Sub
..................................................
I need to have the stopwatch run continually when the form it’s embedded in opens for the users to view the continuous elapsed time a form/process was open. Then after the form is closed I need it to stop and rest to 0.
Can this be accomplished or is there and easier way?