I have this code that calculates workdays based on two dates. Right now it gives me an error if one of the dates is missing. I would like it to give me a null result if one of the dates is missing. Can someone show me what I need to add?
Thanks.
Code:
Public Function Workdays(dteStart As Date, dteEnd As Date) As Long Dim lngDate As Long
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
If IsNull(dteStart) Or IsNull(dteEnd) Then
GoTo Exitpoint
End If
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Holidays", dbOpenSnapshot)
' NetWorkdays = -1
' Check for valid dates.
If IsDate(dteStart) And IsDate(dteEnd) Then
' Strip off any fractional days and just use whole days.
For lngDate = Int(dteStart) To Int(dteEnd)
If Weekday(lngDate, vbMonday) < 6 Then
rst.FindFirst "[Holiday] = #" & Format(lngDate, "mm\/dd\/yyyy") & "#"
If rst.NoMatch Then
Workdays = Workdays + 1
End If
End If
Next lngDate
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exitpoint:
Exit Function
End Function