Calulate Time on a Button Event

alastair69

Registered User.
Local time
Today, 04:57
Joined
Dec 21, 2004
Messages
562
Hello All,

I am using a timer function to hopefully calulate have long a call has lasted, I have setup a rolling clock called "ElapsedTime" and i have the start time running off the P.C. Time this is called "txt_Start", this works fine no issues.

Now comes the fun bit i have a button called "cmd_Finish", i wish the time to be calulated and the total time to be placed in a text box called "txt_Finish" sound easy but nope this would apear not to be.

The Following Setup is used:-
ElapsedTime = "00:00:00"
txt_Start = Time(), formated to LongTime
txt_Finish = Formated to Long Time

Example of what i would like to happen
txt_Start = 10:40:02
ElapsedTime = 00:00:11
txt_Finish = 10:40:13

I have tried the following Code:
*********************************************
Private Sub Command5_Click()
Me.txt_Finish = ([ElapsedTime] + [txt_Start])
End Sub
*********************************************

Can anybody help me on this please.

Alastair :eek:

UPDATE
*****************************RESOLVED THANKS TO ALASTAIR69 (ME) & Allan57********************
 
Last edited:
Adapt the following to suit your needs

Dim dtmStart As Date
Dim dtmEnd As Date
Dim intTimeDiffSecs As Integer

dtmStart = "24/01/06 10:55:23"
dtmEnd = "24/01/06 10:57:11"
intTimeDiffSecs = DateDiff("s", dtmStart, dtmEnd)

MsgBox intTimeDiffSecs
 
The code you very knidley give me produces the following error message "Type mismatch (Error 13)"

I changed your code to this can you see any thing incorrect in it:
******************************************************
Private Sub Command5_Click()
Dim dtmStart As Date
Dim dtmEnd As Date
Dim intTimeDiffSecs As Integer

dtmStart = [txt_Start] & ("hhmmss") '"24/01/06 10:55:23"
dtmEnd = [ElapsedTime] & ("hhmmss") '"24/01/06 10:57:11"
intTimeDiffSecs = DateDiff("s", dtmStart, dtmEnd)

MsgBox intTimeDiffSecs

End Sub
********************************************************

Thank you for your time and help inadvance.

Alastair
 
sorrow did not read your question correctly, try the following

txt_Start = 10:40:02
ElapsedTime = 00:00:11
txt_Finish = 10:40:13

I have tried the following Code:
*********************************************
Private Sub Command5_Click()
Me.txt_Finish = dateadd("s", ElapsedTime, txt_Start)
End Sub
*********************************************

That will add the elapsed time to the start time
 
Still Not working

I still get an error message of "Type mismatch (Error 13)"

Can any body offer some help?
 
Sorted it out all on my own:-

Private Sub Command5_Click()
Dim dtmStart As Date
Dim dtmEnd As Date
Dim intTimeDiffSecs As Integer

dtmStart = [txt_Start] '"24/01/06 10:55:23" & ("hhmmss")
dtmEnd = [ElapsedTime] '"24/01/06 10:57:11" & ("hhmmss")
'intTimeDiffSecs = DateDiff("m", dtmStart, dtmEnd)

'MsgBox intTimeDiffSecs
Me.txt_Finish = (dtmStart + dtmEnd)
End Sub
 
You should search the forum this question has been asked and answered many times.

Ash
 

Users who are viewing this thread

Back
Top Bottom