Ally
Registered User.
- Local time
- Today, 23:05
- Joined
- Sep 18, 2001
- Messages
- 617
I have some code to sort out the datediff between times including dates. I'm calling it from a query. If the date and time fields are empty the time field I'm calculting gives #Error.
The code is:
In the query I've got:
Delay: TimeCount([dischdecdate],[dischdate],[dischdectime], [dischtime])
I've tried variations of IIf and Nz to try and display "" in the field, eg:
Delay1: IIf(nz(TimeCount([dischdecdate],[dischdate],[dischdectime],[dischtime])),TimeCount([dischdecdate],[dischdate],[dischdectime],[dischtime]),"")
but still get #Error. Anyone got any ideas please?
The code is:
Code:
Function TimeCount(a As Date, b As Date, c As Date, d As Date)
Dim x As Integer, y As Integer
y = DateDiff("d", a, b)
If y = 0 Then
'TimeCount = minutes: time2-time1
x = DateDiff("n", c, d)
ElseIf y = 1 Then
'TimeCount = minutes: time1-23:59:59 + minutes: time2 +1 minute
x = DateDiff("n", c, "23:59:59") + DateDiff("n", "0:0:01", d) + 1
Else
x = DateDiff("n", c, "23:59:59") + DateDiff("n", "0:0:01", d) + 1
GoTo 10
End If
TimeCount = x \ 60 & ":" & Format(x Mod 60, "00")
Exit Function
10: TimeCount = (x + (y * 1440) - 1440) \ 60 & ":" & Format(x Mod 60, "00")
End Function
In the query I've got:
Delay: TimeCount([dischdecdate],[dischdate],[dischdectime], [dischtime])
I've tried variations of IIf and Nz to try and display "" in the field, eg:
Delay1: IIf(nz(TimeCount([dischdecdate],[dischdate],[dischdectime],[dischtime])),TimeCount([dischdecdate],[dischdate],[dischdectime],[dischtime]),"")
but still get #Error. Anyone got any ideas please?