HELP! Can someone please help me figure out why the following module is reading weekend days as business days? It should calulate as 2 days instead of three.
Thanks!
Function BusinessDays(EDate, BDate) As Integer
Dim mydb As Database
Dim result As Recordset
Dim Wherestring As String
Dim checkdate As Date
Set mydb = CurrentDb
Set result = mydb.OpenRecordset(“Select Hdate from Holidays”)
If IsNull(EDate) Then Exit Function
checkdate = EDate
BizDays = 0
While checkdate > BDate
If Weekday(checkdate) > 1 And Weekday(checkdate) < 7 Then
Wherestring = "Hdate =#" & checkdate & "#"
With result
.MoveLast
.FindFirst Wherestring
If .NoMatch Then
BizDays = BizDays + 1
End If
End With
End If
checkdate = checkdate - 1
Wend
BusinessDays = BizDays
End Function
Function Days(EDate, BDate) As Integer
Dim mydb As Database
Dim result As Recordset
Dim Wherestring As String
Dim checkdate As Date
Set mydb = CurrentDb
Set result = mydb.OpenRecordset("Select Hdate from Holidays")
If IsNull(EDate) Then Exit Function
checkdate = EDate
BizDays = 0
While checkdate > BDate
Wherestring = “Hdate =#” & checkdate & “#”
With result
.MoveLast
.FindFirst Wherestring
If .NoMatch Then
BizDays = BizDays + 1 End If
End With
checkdate = checkdate – 1
Wend
Days = BizDays
End Function