My country's Holiday dates are in a table tblHolidays with fields. HolidayID,HolidayDate,HolidayName.
The Function:
Expand|Select|Wrap|Line Numbers
- Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
- '-- Return the number of WorkingDays between StartDate and EndDate
- On Error GoTo err_workingDays
- Dim intCount As Integer
- If IsDate(StartDate) And IsDate(EndDate) Then
- If EndDate >= StartDate Then
- intCount = 0
- Do While StartDate < EndDate
- StartDate = StartDate + 1
- If Weekday(StartDate, vbMonday) <= 5 And _
- IsNull(DLookup("[Holiday]", "tblHolidays", _
- "[HolDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
- intCount = intCount + 1
- End If
- Loop
- WorkingDays = intCount
- Else
- WorkingDays = -1 '-- To show an error
- End If
- Else
- WorkingDays = -1 '-- To show an error
- End If
- exit_workingDays:
- Exit Function
- err_workingDays:
- MsgBox "Error No: " & Err.Number & vbCr & _
- "Description: " & Err.Description
- Resume exit_workingDays
- End Function
Can someone figure this out? Or is it another field that I need to create? I know this is simple for some people but please help.
Thanks