I'm trying to create a count down based on two variables. The first is the current time, the second is a departure time that is entered by the operator. The code I have so far is listed below.
Private Sub txtdeptime_LostFocus()
Dim currtime As Date
Dim deptime As Date
Dim split As Date
currtime = CDate(Me.txtcurrtime.Value)
deptime = CDate(Me.txtdeptime.Value)
split = ElapsedTime(deptime, currtime)
Me.txtsplittime.Value = Format(split, "hh:nn:ss")
End Sub
Function ElapsedTime(currtime As Date, deptime As Date) As Date
ElapsedTime = deptime - currtime
End Function
Two things are going wrong. First, my currtime is base on the Time() function and before this code, it kept the current time, now it displays the time that the form opened and then stops. Second, I can't figure out how to get the clock to count back to zero minutes and seconds. I've tried several things including DateDiff and DateAdd("ss",-1, "split"), but I just can't make it work. I'm assuming it has something to do with aggragate's, but I'm not sure how to code this to make it work, can anyone help?
Private Sub txtdeptime_LostFocus()
Dim currtime As Date
Dim deptime As Date
Dim split As Date
currtime = CDate(Me.txtcurrtime.Value)
deptime = CDate(Me.txtdeptime.Value)
split = ElapsedTime(deptime, currtime)
Me.txtsplittime.Value = Format(split, "hh:nn:ss")
End Sub
Function ElapsedTime(currtime As Date, deptime As Date) As Date
ElapsedTime = deptime - currtime
End Function
Two things are going wrong. First, my currtime is base on the Time() function and before this code, it kept the current time, now it displays the time that the form opened and then stops. Second, I can't figure out how to get the clock to count back to zero minutes and seconds. I've tried several things including DateDiff and DateAdd("ss",-1, "split"), but I just can't make it work. I'm assuming it has something to do with aggragate's, but I'm not sure how to code this to make it work, can anyone help?