jonathanchye
Registered User.
- Local time
- Today, 15:59
- Joined
- Mar 8, 2011
- Messages
- 448
I have a function which calculates the Net work days taken from 2 date fields. (Start and End date)
I've ran a query using the function and it looks fine except some fields returning "#Error'
It seems this only applies to records with an empty EndDate field. This is causing me problems as I can't apply a Criteria to this query.
I've modified my function to return specific values in this case but it doesn't seem to work. Below is my function (I hope someone can spot my error?) Thanks.
I've ran a query using the function and it looks fine except some fields returning "#Error'
It seems this only applies to records with an empty EndDate field. This is causing me problems as I can't apply a Criteria to this query.
I've modified my function to return specific values in this case but it doesn't seem to work. Below is my function (I hope someone can spot my error?) Thanks.
Code:
Public Function NetWorkdays(dteStart As Date, dteEnd As Date) As Long
Dim lngDate As Long
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
If IsNull(DLookup("[HolidayDate]", "tblHolidays", "[HolidayDate] = " & lngDate)) Then
NetWorkdays = NetWorkdays + 1
End If
End If
Next lngDate
' End If
ElseIf IsDate(dteEnd) = False Then NetWorkdays = -1
ElseIf IsEmpty(dteEnd) Then NetWorkdays = -2
End If
End Function