A
Accel
Guest
I am attempting to track how long a record is open or is the current record on a Form.
What I have is a bound field on a form named "ElapsedTime".
(I am adding this to determine the amount of time spent working on a report.
I enter the report information in the database as a record.
I then review the report and add comments to the database based on my review of the report.
Many times I am not able to complete the review in one setting. I want to be able to continue timing when I return to the report.)
Each time I go to a particular record I want the amount of time I have spent on the record to appear in "ElapsedTime" and be saved in "ElapsedTime".
If I click the Start button I want the timer to start.
If I leave the record I want the timer to stop.
If I return to the record, and I click the Start button, I want the amount of time to continue from where it ended when I last opened the record.
I am using the Stopwatch Form described in Microsoft Knowledge Base Article number 233275 but I need help modifing the code to accomplish the above. (Code below)
How do I modify the code in 233275 so that "ElapsedTime" starts from whatever time has previously elapsed for the record.
and
so that the timer stops when I leave the record or I click the stop button.
Option Compare Database
Option Explicit
Dim TotalElapsedMilliSec As Long
Dim StartTickCount As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub cmdStartStop_Click()
If Me.TimerInterval = 0 Then
StartTickCount = GetTickCount()
Me.TimerInterval = 15
Me!cmdStartStop.Caption = "&STOP"
Me.cmdStartStop.ForeColor = RGB(255, 0, 0)
Me.cmdStartStop.FontSize = "12"
Me!cmdReset.Enabled = False
Else
TotalElapsedMilliSec = TotalElapsedMilliSec + (GetTickCount() - StartTickCount)
Me.TimerInterval = 0
Me!cmdStartStop.Caption = "Start the &Timer"
Me.cmdStartStop.ForeColor = RGB(0, 64, 128)
Me.cmdStartStop.FontSize = "8"
Me!cmdReset.Enabled = True
End If
End Sub
Private Sub cmdClose_Click()
DoCmd.Close acForm, "frmStopWatch", acSaveNo
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 cmdReset_Click()
TotalElapsedMilliSec = 0
Me!ElapsedTime = "00:00:00:00"
End Sub
Thanks
Accel
What I have is a bound field on a form named "ElapsedTime".
(I am adding this to determine the amount of time spent working on a report.
I enter the report information in the database as a record.
I then review the report and add comments to the database based on my review of the report.
Many times I am not able to complete the review in one setting. I want to be able to continue timing when I return to the report.)
Each time I go to a particular record I want the amount of time I have spent on the record to appear in "ElapsedTime" and be saved in "ElapsedTime".
If I click the Start button I want the timer to start.
If I leave the record I want the timer to stop.
If I return to the record, and I click the Start button, I want the amount of time to continue from where it ended when I last opened the record.
I am using the Stopwatch Form described in Microsoft Knowledge Base Article number 233275 but I need help modifing the code to accomplish the above. (Code below)
How do I modify the code in 233275 so that "ElapsedTime" starts from whatever time has previously elapsed for the record.
and
so that the timer stops when I leave the record or I click the stop button.
Option Compare Database
Option Explicit
Dim TotalElapsedMilliSec As Long
Dim StartTickCount As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub cmdStartStop_Click()
If Me.TimerInterval = 0 Then
StartTickCount = GetTickCount()
Me.TimerInterval = 15
Me!cmdStartStop.Caption = "&STOP"
Me.cmdStartStop.ForeColor = RGB(255, 0, 0)
Me.cmdStartStop.FontSize = "12"
Me!cmdReset.Enabled = False
Else
TotalElapsedMilliSec = TotalElapsedMilliSec + (GetTickCount() - StartTickCount)
Me.TimerInterval = 0
Me!cmdStartStop.Caption = "Start the &Timer"
Me.cmdStartStop.ForeColor = RGB(0, 64, 128)
Me.cmdStartStop.FontSize = "8"
Me!cmdReset.Enabled = True
End If
End Sub
Private Sub cmdClose_Click()
DoCmd.Close acForm, "frmStopWatch", acSaveNo
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 cmdReset_Click()
TotalElapsedMilliSec = 0
Me!ElapsedTime = "00:00:00:00"
End Sub
Thanks
Accel