I have a Microsoft access 2010 Query that calls the below function. The function works fine when dtdisch is populated however when it is null the query shows #Error. The Errhandler in the function does not execute What am I missing? I've replaced the IsNull(dtdisch) to IsDate(dtdisch) but got the same result.
Public Function LOS(ByRef dtadmit As Date, dtdisch As Date) As Long
Dim tmpdt As Date
On Error GoTo errhandler
If IsNull(dtdisch) Then
tmpdt = Date
Else
tmpdt = dtdisch
End If
LOS = DateDiff("d", dtadmit, tmpdt)
If LOS = 0 Then LOS = 1
ExitHandler:
Exit Function
errhandler:
MsgBox Err.Description, vbOKOnly, "Error"
Resume ExitHandler
End Function