I adjusted the expression, still no go. Here's the code for
"ElapsedTimeString":
Public Function HoursAndMinutes(interval As Variant) As String
'*************************************************************
' Function HoursAndMinutes(interval As Variant) As String
' Returns time interval formatted as a hours:minutes string
'*************************************************************
Dim totalminutes As Long, totalseconds As Long
Dim hours As Long, minutes As Long, seconds As Long
If IsNull(interval) = True Then Exit Function
hours = Int(CSng(interval * 24))
' 1440 = 24 hrs * 60 mins
totalminutes = Int(CSng(interval * 1440))
minutes = totalminutes Mod 60
' 86400 = 1440 * 60 secs
totalseconds = Int(CSng(interval * 86400))
seconds = totalseconds Mod 60
' Round up the minutes and adjust hours
If seconds > 30 Then minutes = minutes + 1
If minutes > 59 Then hours = hours + 1: minutes = 0
HoursAndMinutes = hours & ":" & Format(minutes, "00")
End Function
Public Function ElapsedTimeString(dateTimeStart As Date, _
dateTimeEnd As Date) _
As String
'*************************************************************
' Function ElapsedTimeString(dateTimeStart As Date,
' dateTimeEnd As Date) As String
' Returns the time elapsed between a starting Date/Time and
' an ending Date/Time formatted as a string that looks like
' this:
' "10 days, 20 hours, 30 minutes, 40 seconds".
'*************************************************************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String, seconds As String
If IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function
interval = dateTimeEnd - dateTimeStart
days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")
seconds = Format(interval, "s")
' Days part of the string
str = IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days"))
str = str & IIf(days = 0, "", _
IIf(hours & minutes & seconds <> "000", ", ", " "))
' 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"))
ElapsedTimeString = IIf(str = "", "0", str)
End Function
Many thanks, MC
Marshall Barton said:
Michaelcip said:
I got an error message that said that "The expression you entered has a
function containing the wrong # of arguements" - though expression works
properly on its own. This is my code for my calculation field now,
interjecting your suggestion:
"=IIf(IsError(ElapsedTimeString([StartTime],[EndTime]), Null,
ElapsedTimeString([StartTime],[EndTime])))" The "ElapsedTimeString" is code
that I got from that article located in the Microsoft self-help site; like I
was saying, this code is working as it states, but it produces an error
message that I'm trying to hide.
No, I have no other thoughts. Let's fix that expression
before going off on tangents:
=IIf(IsError(ElapsedTimeString([StartTime],[EndTime])),
Null, ElapsedTimeString([StartTime],[EndTime]))
Once you get that simple minded workaround correct, you
should analyze the code in the function to figure out why it
causes #Error
If you need help with a specific question about the code in
the function, post a url to the web page and a Copy/Paste of
your version.