Hi all,
I'm trying to add times on a report and make the sum appear in hh:mm:ss format regardless of how many hours have elapsed. The way Access is handling this by default is rolling over to d:hh:mm:ss when 24 hours is reached.
I have used the following code:
This is reformatting the sum exactly how I'd like and is working perfectly for one field (column of time values) in a report. However, when I call the function for the second field (another column of time values), I get an automation error 440 when trying to run the report and get #Error for all of those fields. I'm adding =TotalTime([field]) to the control source to call the function. Am I missing something?
I'm trying to add times on a report and make the sum appear in hh:mm:ss format regardless of how many hours have elapsed. The way Access is handling this by default is rolling over to d:hh:mm:ss when 24 hours is reached.
I have used the following code:
Code:
Public Function TotalTime(dblTimeDif) As String
Dim intDays As Integer
Dim dblHrs As Double
Dim intHours As Integer
Dim dblMinutes As Double
Dim intMinutes As Integer
Dim dblSeconds As Double
Dim intSeconds As Integer
Dim intTime As Integer
Dim intFraction As Integer
Dim strResult As String
intDays = Int(dblTimeDif)
dblHrs = (dblTimeDif - intDays) * 24
intHours = Int(dblHrs)
dblMinutes = (dblHrs - intHours) * 60
intHours = intHours + (intDays * 24)
intMinutes = Int(dblMinutes)
dblSeconds = (dblMinutes - intMinutes) * 60
intSeconds = Int(dblSeconds)
strResult = Str(intHours) & ":"
If intMinutes < 10 Then
strResult = strResult & "0" & Trim(Str(intMinutes))
Else
strResult = strResult & Trim(Str(intMinutes))
End If
strResult = strResult & ":"
If intSeconds < 10 Then
strResult = strResult & "0" & Trim(Str(intSeconds))
Else
strResult = strResult & Trim(Str(intSeconds))
End If
TotalTime = strResult
End Function
This is reformatting the sum exactly how I'd like and is working perfectly for one field (column of time values) in a report. However, when I call the function for the second field (another column of time values), I get an automation error 440 when trying to run the report and get #Error for all of those fields. I'm adding =TotalTime([field]) to the control source to call the function. Am I missing something?