Public Function GetNetWorkDays3( _
ByVal datDateFrom As Variant, _
ByVal datDateTo As Variant, _
ByVal strCountry As String, _
Optional ByVal booExcludeHolidays As Boolean) As Long
Dim swp As Variant
Dim I As Variant
Dim lngDays As Long
Dim strDateFrom As String
Dim strDateTo As String
Dim strFilter As String
Dim strSQL As String
Dim lngHolidays As Long
Dim rs As DAO.Recordset
Dim tempDate As Date
' Name of table with holidays.
Const cstrTableHoliday As String = "tbl_eDealHolidays"
' Name of date field in holiday table.
Const cstrFieldHoliday As String = "holDate"
Const cstrCountryField As String = "CountryCode"
If IsNull(datDateFrom) Then datDateFrom = Date
If IsNull(datDateTo) Then datDateTo = Date
If datDateFrom > datDateTo Then
swp = datDateFrom
datDateFrom = datDateTo
datDateTo = swp
End If
datDateFrom = CDate(Format(datDateFrom, "mm/dd/yyyy"))
datDateTo = CDate(Format(datDateTo, "mm/dd/yyyy"))
tempDate = datDateFrom
While tempDate <= datDateTo
If InStr("/Saturday/Sunday/", Format(tempDate, "dddd")) = 0 Then
lngDays = lngDays + 1
End If
tempDate = DateAdd("d", 1, tempDate)
Wend
If booExcludeHolidays And lngDays > 0 Then
strDateFrom = Format(datDateFrom, "mm/dd/yyyy")
strDateTo = Format(datDateTo, "mm/dd/yyyy")
strFilter = "[" & cstrCountryField & "] = " & Chr(34) & strCountry & Chr(34) & " "
strFilter = strFilter & " And " & _
"[" & cstrFieldHoliday & "] Between #" & strDateFrom & "# And #" & strDateTo & "#;"
strSQL = "SELECT [" & cstrFieldHoliday & "] FROM [" & cstrTableHoliday & "] " & _
"WHERE " & strFilter
Set rs = DBEngine(0)(0).OpenRecordset(strSQL)
With rs
If Not (.BOF And .EOF) Then .MoveFirst
While Not .EOF
If InStr("/Saturday/Sunday/", Format(rs(0).value, "dddd")) = 0 Then
lngHolidays = lngHolidays + 1
End If
.MoveNext
Wend
.Close
End With
Set rs = Nothing
End If
GetNetWorkDays3 = lngDays - lngHolidays
End Function