I am using the function below to calculate a field that excludes weekends and holidays. The weekends are excluded as it is now, but when I try to add in code to exclude holidays I am getting errors. The code for the holidays is in bold and a couple of the errors are Loop without Do so I remove the Loop then I get a Else without If. It's very close but I can not seem to fix this issue. Thank you
.
VB
VB
Code:
Option Compare Database
Public Function WorkingDays(Due_Date As Date, Result_Date As Date) As Integer
'-- Return the number of WorkingDays between Due_Date and Result_Date
On Error GoTo err_workingDays
Dim intCount As Integer
If IsDate(Due_Date) And IsDate(Result_Date) Then
If Result_Date >= Due_Date Then
intCount = 0
Do While Due_Date < Result_Date
Due_Date = Due_Date + 1
If Weekday(Due_Date, vbMonday) <= 5 Then
'[B]-- Holiday code
If Weekday(Due_Date, vbMonday) <= 5 And _
IsNull(DLookup("[Description]", "Holidays", _
"[Holiday] = " & Format(Due_Date, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
intCount = intCount + 1
Loop
End If
WorkingDays = intCount
Else
WorkingDays = -1 '-- To show an error
End If
Else
WorkingDays = -1 '-- To show an error
End If
exit_workingDays:
Exit Function [/B]
err_workingDays:
MsgBox "Error No: " & Err.Number & vbCr & _
"Description: " & Err.Description
Resume exit_workingDays
End Function