G
Guest
I have a subform where I am calculating time difference between current time
and the last update. I have a text box txtTimeDiff with control source
=ElapsedTimeString([Last Update],Now())
Is it possible to add timer so this text box and time difference can be
updated every second?
Here is ElapsedTimeString function
Public Function ElapsedTimeString(Date1 As Date, _
Date2 As Date) _
As String
Dim interval As Double, str As String, days As Variant
Dim hours As String, Minutes As String, seconds As String
If IsNull(Date1) = True Or _
IsNull(Date2) = True Then Exit Function
interval = Date2 - Date1
days = Fix(CSng(interval))
hours = Format(interval, "h")
Minutes = Format(interval, "n")
seconds = Format(interval, "s")
' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(Minutes & seconds <> "00", ", ", " "))
' Minutes part of the string
str = str & IIf(Minutes = "0", "", _
IIf(Minutes = "1", Minutes & " Minute", _
Minutes & " Minutes"))
str = str & IIf(Minutes = "0", "", _
IIf(seconds <> "0", ", ", " "))
'Seconds part of the string
str = str & IIf(seconds = "0", "", _
IIf(seconds = "1", seconds & " Second", _
seconds & " Seconds"))
If seconds > 30 Then Minutes = Minutes + 1
If Minutes > 59 Then hours = hours + 1: Minutes = 0
ElapsedTimeString = IIf(str = "", "0", str)
End Function
and the last update. I have a text box txtTimeDiff with control source
=ElapsedTimeString([Last Update],Now())
Is it possible to add timer so this text box and time difference can be
updated every second?
Here is ElapsedTimeString function
Public Function ElapsedTimeString(Date1 As Date, _
Date2 As Date) _
As String
Dim interval As Double, str As String, days As Variant
Dim hours As String, Minutes As String, seconds As String
If IsNull(Date1) = True Or _
IsNull(Date2) = True Then Exit Function
interval = Date2 - Date1
days = Fix(CSng(interval))
hours = Format(interval, "h")
Minutes = Format(interval, "n")
seconds = Format(interval, "s")
' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(Minutes & seconds <> "00", ", ", " "))
' Minutes part of the string
str = str & IIf(Minutes = "0", "", _
IIf(Minutes = "1", Minutes & " Minute", _
Minutes & " Minutes"))
str = str & IIf(Minutes = "0", "", _
IIf(seconds <> "0", ", ", " "))
'Seconds part of the string
str = str & IIf(seconds = "0", "", _
IIf(seconds = "1", seconds & " Second", _
seconds & " Seconds"))
If seconds > 30 Then Minutes = Minutes + 1
If Minutes > 59 Then hours = hours + 1: Minutes = 0
ElapsedTimeString = IIf(str = "", "0", str)
End Function