VB Code - TechRepublic
General discussion
December 14, 2000 at 05:10 AM
tlscruggs

VB Code

by tlscruggs . Updated 25 years, 4 months ago

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

This discussion is locked

All Comments