MsLady
Traumatized by Access
- Local time
- Today, 04:40
- Joined
- Jun 14, 2004
- Messages
- 438
I have attached the db below. It's a smalldb with just one form
I have a function called ElapsedTimeString that produces the Hours, minutes, and seconds time elapsed between two time fields (my function module is below).
I have a continous form that i use for dataentry.
the fields are Username, startime, endtime, and an unbound control called txtTotalTimeSpent just to display the total time to the user.
The control source on txtTotalTimeSpent is:
Now whenever there is a new record, "#error" automatically displayes in the textbox (txtTotalTimeSpent).
I have attached the file, please how do i get rid of this #error. I have tried error handling to do nohting no luck. I have tried everything ican think of. Can anyone help give it a try?

I have a function called ElapsedTimeString that produces the Hours, minutes, and seconds time elapsed between two time fields (my function module is below).
I have a continous form that i use for dataentry.
the fields are Username, startime, endtime, and an unbound control called txtTotalTimeSpent just to display the total time to the user.
The control source on txtTotalTimeSpent is:
Code:
=ElapsedTimeString([timeStart],[timeStop])))
'I tried this also, still no luck
=IIf(IsNull([timeStart]) Or IsNull([timeStop]),[totalTimeSpent].Value="",(ElapsedTimeString([timeStart],[timeStop])))
I have attached the file, please how do i get rid of this #error. I have tried error handling to do nohting no luck. I have tried everything ican think of. Can anyone help give it a try?
Code:
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
ElapsedTimeString = 0
Exit Function
End If
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