Ihave have found this code that work of the ontimer property on a form and was wondering hw to make it STOP when it reaches 0, as of now it starts counting again after it reaches zero, please help thanks,
Function YMWDHMS(ByVal SecondsIn As Variant) As String
Dim TempDate As Date
Dim Date1 As Date
Dim Date2 As Date
Dim NumOfMonths As Long
Dim NumOfWeeks As Long
Dim NumOfDays As Long
Dim NumOfHMS As Double
Dim TSerial1 As Double
Dim TSerial2 As Double
Date2 = Now
Date1 = DateAdd("s", -SecondsIn, Date2)
NumOfYears = DateDiff("yyyy", Date1, Date2)
TSerial1 = TimeSerial(Hour(Date1), Minute(Date1), Second(Date1))
TSerial2 = TimeSerial(Hour(Date2), Minute(Date2), Second(Date2))
NumOfHMS = 24 * (TSerial2 - TSerial1)
If NumOfHMS < 0 Then
NumOfHMS = NumOfHMS + 24
Date2 = DateAdd("d", -1, Date2)
End If
NumOfDays = Abs(DateDiff("d", Date1, Date2))
NumOfWeeks = NumOfDays \ 7
NumOfDays = NumOfDays Mod 7
' Format the Years, Months, Weeks, Days part
YMWDHMS = YMWDHMS & CStr(NumOfWeeks) & _
" week" & IIf(NumOfWeeks = 1, "", "s ")
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(NumOfDays) & _
" day" & IIf(NumOfDays = 1, "", "s ")
' Format the Hours, Minutes and Seconds part
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(Int(NumOfHMS)) & _
" Hour" & IIf(Int(NumOfHMS) = 1, "", "s ")
NumOfHMS = 60 * (NumOfHMS - Int(NumOfHMS))
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(Int(NumOfHMS)) & _
" Minute" & IIf(Int(NumOfHMS) = 1, "", "s ")
NumOfHMS = 60 * (NumOfHMS - Int(NumOfHMS))
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(CInt(NumOfHMS)) & _
" second" & IIf(Int(NumOfHMS) = 1, "", "s")
End Function
Function YMWDHMS(ByVal SecondsIn As Variant) As String
Dim TempDate As Date
Dim Date1 As Date
Dim Date2 As Date
Dim NumOfMonths As Long
Dim NumOfWeeks As Long
Dim NumOfDays As Long
Dim NumOfHMS As Double
Dim TSerial1 As Double
Dim TSerial2 As Double
Date2 = Now
Date1 = DateAdd("s", -SecondsIn, Date2)
NumOfYears = DateDiff("yyyy", Date1, Date2)
TSerial1 = TimeSerial(Hour(Date1), Minute(Date1), Second(Date1))
TSerial2 = TimeSerial(Hour(Date2), Minute(Date2), Second(Date2))
NumOfHMS = 24 * (TSerial2 - TSerial1)
If NumOfHMS < 0 Then
NumOfHMS = NumOfHMS + 24
Date2 = DateAdd("d", -1, Date2)
End If
NumOfDays = Abs(DateDiff("d", Date1, Date2))
NumOfWeeks = NumOfDays \ 7
NumOfDays = NumOfDays Mod 7
' Format the Years, Months, Weeks, Days part
YMWDHMS = YMWDHMS & CStr(NumOfWeeks) & _
" week" & IIf(NumOfWeeks = 1, "", "s ")
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(NumOfDays) & _
" day" & IIf(NumOfDays = 1, "", "s ")
' Format the Hours, Minutes and Seconds part
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(Int(NumOfHMS)) & _
" Hour" & IIf(Int(NumOfHMS) = 1, "", "s ")
NumOfHMS = 60 * (NumOfHMS - Int(NumOfHMS))
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(Int(NumOfHMS)) & _
" Minute" & IIf(Int(NumOfHMS) = 1, "", "s ")
NumOfHMS = 60 * (NumOfHMS - Int(NumOfHMS))
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(CInt(NumOfHMS)) & _
" second" & IIf(Int(NumOfHMS) = 1, "", "s")
End Function