A bound form provides an event that tells you when it becomes "Dirty," so that would be an ideal place to start the editing clock. A user can view a record without editing it (or "Dirtying" it), so if you want to know when a user is merely viewing a record you could use the Form_Current event, but is that what you want?.
Another event named "Form_AfterUpdate" is fired after the record is saved, which is where the stop time should be recorded.
To capture the times, instead of using textboxes, you can use module-level variables for the form, placed in the declarations section of the module:
Code:
Option Compare Database
Option Explicit
Private mblnDirty As Boolean [green]'is the form dirty?[/green]
Private mdatStartTime As Date [green]'the start time[/green]
Private mdatEndTime As Date [green]'the end time[/green]
Then create a function that performs the calculation:
Code:
Sub UpdateEditingTime()
Dim datElapsed As String
If mblnDirty = True Then
mdatEndTime = Now
datElapsed = Format(mdatEndTime - mdatStartTime, "hh:mm:ss")
MsgBox "Editing Time: " & datElapsed
mblnDirty = False
End If
End Sub
Then you can set the mblnDirty variable and the start time in the Form_Dirty() event:
Code:
Private Sub Form_Dirty(Cancel As Integer)
mblnDirty = True
mdatStartTime = Now
End Sub
Finally, call the function after the editing is completed in the Form_AfterUpdate() event:
Code:
Private Sub Form_AfterUpdate()
Call UpdateEditingTime
End Sub
This example merely displays a message box showing the editing time, so you'll have to add a line of code to put the time in a textbox for storage.
VBSlammer
![[sleeping] [sleeping] [sleeping]](/data/assets/smilies/sleeping.gif)
Unemployed in Houston, Texas