Time How Long A Record is the current record.

  • Thread starter Thread starter Accel
  • Start date Start date
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
 
Sems like it would be easier to say just hold minutes. You can just capture Now() when you start, and Now() when you end, use DATEDIFF to give you minutes and add that to your field (initialized to zero on a new record). Calculating from minutes for total time should be easy enough.
Just my thoughts.
 
Or, for accuracy down to milliseconds:

Put this in a standalone module

Code:
Public Declare Function WWindowsStart Lib "WINMM" Alias _
        "timeGetTime" () As Long

When you open the form, you can get the value of WWindowsStart and when you close the form you, again, take the value of WWindowsStart. Subtract the latter from the former and you'll get the number of milliseconds spent on a record.
 
Need more help

Mile-O-Phile said:
Or, for accuracy down to milliseconds:

Put this in a standalone module

Code:
Public Declare Function WWindowsStart Lib "WINMM" Alias _
        "timeGetTime" () As Long

When you open the form, you can get the value of WWindowsStart and when you close the form you, again, take the value of WWindowsStart. Subtract the latter from the former and you'll get the number of milliseconds spent on a record.

Thank you Mile-O-Phile but I could use a more detailed explanation or an example to look at.

Accel
 
Tried and Got stuck

FoFa said:
Sems like it would be easier to say just hold minutes. You can just capture Now() when you start, and Now() when you end, use DATEDIFF to give you minutes and add that to your field (initialized to zero on a new record). Calculating from minutes for total time should be easy enough.
Just my thoughts.

Thank you for your suggestion FoFa.
I tried this and got stuck on Adding the time spent should I need to visit a record more than once. ????
Accel
 

Users who are viewing this thread

Back
Top Bottom