In the below code, if time is less than 0, I would like for the entire phrase to read "EXPIRED". However, currently, it shows EXPIRED and then the number of hours minutes and seconds. I don't want it to show any hours minutes and seconds. Could someone help? Thanks!!
Public Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
'************************************************* ********************
' Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
' Returns the time elapsed between a fixed number and starting Date/Time and an ending
' Date/Time formatted as a string that looks like this:
' "10 days, 20 hours, 30 minutes".
'************************************************* ********************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String
If IsNull(TimeDays) = True Or _
IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function
interval = (TimeDays - (dateTimeEnd - dateTimeStart))
days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")
' Days part of the string
str = IIf(days < 0, "EXPIRED!", _
IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days")))
str = str & IIf(days = 0, "", _
IIf(hours & minutes <> "00", ", ", " "))
' Hours part of the string
str = str & IIf(hours < 0, "", _
IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours")))
str = str & IIf(hours = "0", "", _
IIf(minutes <> "0", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes < 0, "", _
IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", minutes & " Minutes")))
TimeRemaining = IIf(str = "", "0", str)
End Function
Public Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
'************************************************* ********************
' Function TimeRemaining(TimeDays As Integer, dateTimeStart As Date, dateTimeEnd As Date) As String
' Returns the time elapsed between a fixed number and starting Date/Time and an ending
' Date/Time formatted as a string that looks like this:
' "10 days, 20 hours, 30 minutes".
'************************************************* ********************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String
If IsNull(TimeDays) = True Or _
IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function
interval = (TimeDays - (dateTimeEnd - dateTimeStart))
days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")
' Days part of the string
str = IIf(days < 0, "EXPIRED!", _
IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days")))
str = str & IIf(days = 0, "", _
IIf(hours & minutes <> "00", ", ", " "))
' Hours part of the string
str = str & IIf(hours < 0, "", _
IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours")))
str = str & IIf(hours = "0", "", _
IIf(minutes <> "0", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes < 0, "", _
IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", minutes & " Minutes")))
TimeRemaining = IIf(str = "", "0", str)
End Function