Timer

.Justin

Registered User.
Local time
Today, 11:06
Joined
Jun 29, 2009
Messages
38
Good Evening,

I am looking at putting in a timer function on my form. The form is for escalation call backs so we need to start the timer when starting the call back and end the timer at the end of the call back.

What I would like is for a button to be pressed by the user and the system to enter the time it was pressed into a field and then once the user is finished they press it again for it to put the time into another field. After this I would like a field to calculate the amount of time spent on the call.

Does this make sense? If so how do i go about doing it?
 
Making some assumptions, here are some step-by-steps for this kind of routine:

You'll need three textboxes, StartTime, EndTime and ElapsedTime.

StartTime and EndTime will be bound to fields (Date/Time Datatype) in the underlying table.

ElapsedTime will be an unbound field. Calculated fields, as a rule, should not be bound to a table, but should merely be re-calculated as needed. In the Properties Pane set its Format as General Number.

Place a Command Button on your form, name it TimerButton. Set its Caption as Call Start.

Now place this code in the form's code module:
Code:
Private Sub Form_Current()
If Me.NewRecord Then
 Me.TimerButton.Caption = "Call Start"
 Me.ElapsedTime = Null
Else
Me.TimerButton.Caption = "Call End"
 Me.ElapsedTime = (DateDiff("s", Me.StartTime, Me.EndTime) \ 60) & ":" & (DateDiff("s", Me.StartTime, Me.EndTime) Mod 60)
End If
End Sub

Private Sub TimerButton_Click()
 If Me.TimerButton.Caption = "Call Start" Then
  Me.StartTime = Now
  Me.TimerButton.Caption = "Call End"
 Else
  Me.EndTime = Now
  Me.ElapsedTime = (DateDiff("s", Me.StartTime, Me.EndTime) \ 60) & ":" & (DateDiff("s", Me.StartTime, Me.EndTime) Mod 60)
 End If
End Sub

This code will toggle the Caption and function of the single TimerButton.

When first clicked it will place the date/time in the StartTime textbox and change the button's Caption to "Call End".

When clicked the second time it will place the date/time in the EndTime textbox and calculate the elapsed time and place it in the ElapsedTime Textbox, using the format mm:ss.

When viewing an existing record, the ElapsedTime will be re-calculated, using the Form_Current event.
Linq ;0)>
 
Last edited:

Users who are viewing this thread

Back
Top Bottom