Record time between 2 events and store it in a field.

the-m0th

Registered User.
Local time
Today, 21:19
Joined
Apr 14, 2015
Messages
51
Hi Everyone,

I'm trying to add a timer to my form at work that will record the time between pressing one button and then pressing another (the dial and hangup button so i can check how long a call rang for.) and then input the time into a field (or text box on the form that is linked to the field, i ain't fussy) but i'm totally stuck on where to start. If anyone could offer me some advice or a starting point i would be very appreciative.

Thanks Again.
Wayne
 
'store it in minutes (n)

= DateDiff("n",[startDate],[EndDate])
 
@ranman256 thanks for the advice, where would you use that code? i've tried to use it in a calculated field but it won't let me.

cheers
Wayne
 
no need to add timer on the form:

on your form's code behind, create a public variable:

private mdlTotalTimeInSec As double

on the click event of ring button:

private sub ring_click()
mdlTotalTimeInSec =timer
end sub

on the click event of hung button:

private sub hung_click()
dim m as double
m=timer
'this is in seconds
m = mdlTotalTimeInSec - m
Me.yourTextboxToDisplay = m
' if you want in minute:seconds format
'Me.yourTextboxToDisplay = (m\60) & ":" (m mod 60)
end sub
 
Arnel? Isn't TIMER the integer milliseconds (since midnight)? Or am I thinking of something else?

Another approach: I am taking the "Ring" button as the starting event and the "Hung" button as the ending event. Reverse the start and end variables if that is wrong...

In the form's declaration area

Code:
Dim TimeStart as Double
Dim TimeEnd as Double

Then, the "click" events:

Code:
private sub ring_click()
TimeStart = Now()
end sub

Code:
private sub hung_click()
dim TimeElapsed as double

TimeEnd = Now()               'this is in days.fractions

TimeElapsed = TimeEnd - TimeStart

Me.yourTextboxToDisplay = FormatDateTime( "hhh:mm:ss", TimeElapsed)

end sub

This will cause the elapsed time to be shown as hours:minutes:seconds (with no date).
 

Users who are viewing this thread

Back
Top Bottom