Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function basWeekdays(StrtDt As Date, NumDays As Integer) As Date
'Usage:
'? basWeekdays(#1/10/01#, 23) Returns 2/16/01
'? basWeekdays(#1/10/01#, 260) Returns 1/31/02
'(But - Of Course - You need to Know the Holiday List)
'So "See" the Acompanying Table
Dim dbs As Database
Dim qdf As QueryDef
Dim rst As Recordset
Dim EndDt As Date 'Trial Date For end of Interval
Dim BeginDt As Date 'Start Date - Adjusted to NOT be Sat or Sun
Dim FinishDt As Date 'Real Ending Date
Dim DateDir As Integer 'Date Direction Flag
Dim MyDOW As Integer 'DayOfWeek Number for the Date
Dim DaysToAdd As Integer 'Number of Days to Adjust StrtDt to get to the
Dim Idx As Integer
Dim MyHoliDay As Date 'Date to Check For In Holiday Table
Dim strSQL As String
DateDir = Sgn(NumDays) 'Find out if we are going forward or Backward
Select Case Choose(WeekDay(StrtDt), 1, 2, 3, 4, 5, 6, 7)
Case Is = 7 Or 1 'Saturday Or Sunday
'Weekend, so Begin Day needs to be
If (DateDir = -1) Then 'Backwards
DaysToAdd = 6 - WeekDay(StrtDt)
BeginDt = DateAdd("d", DaysToAdd + DateDir, StrtDt)
Else
DaysToAdd = 2 - WeekDay(StrtDt)
BeginDt = DateAdd("d", DaysToAdd + 7 + DateDir, StrtDt)
End If
Case Else
'Weekday is a workday, So BeginDt is just the Start Day
BeginDt = StrtDt
End Select
EndDt = DateAdd("d", (7 / 5) * NumDays + DateDir, BeginDt) 'Trial End Date
MyDOW = Choose(WeekDay(EndDt), 1, 2, 3, 4, 5, 6, 7) 'Day of Week
Select Case MyDOW
Case Is = 1 'Sunday
'Again, Need to adjust the end date to NOT be a weekend day
If (DateDir > 0) Then 'Going Forward
DaysToAdd = 1
Else 'Backwards
DaysToAdd = -2
End If
Case Is = 7 'Saturday
'Again, Need to adjust the end date to NOT be a weekend day
If (DateDir > 0) Then 'Forwards
DaysToAdd = 2
Else
DaysToAdd = -1
End If
Case Else
'No adjustment necessary. End Date falls on a non-weekend day
DaysToAdd = 0
End Select
FinishDt = DateAdd("d", DaysToAdd, EndDt)
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryNumHoliDayIncl")
strSQL = "SELECT Count(tblHolidays.HoliDate) AS NumHoliD "
strSQL = strSQL & "FROM tblHolidays "
strSQL = strSQL & "HAVING (((tblHolidays.HoliDate) Between "
strSQL = strSQL & Chr(35) & BeginDt & Chr(35) & " And "
strSQL = strSQL & Chr(35) & FinishDt & Chr(35) & " And "
strSQL = strSQL & "Weekday([Holidate])<>1 And Weekday([Holidate])<>1));"
qdf.SQL = strSQL
Set rst = dbs.OpenRecordset("qryNumHolidayIncl", dbOpenDynaset)
DaysToAdd = rst!NumHoliD
'Now, DaysToAdd represent the number of Holidays in the DateRange
'We need to adjust the End Date (AGAIN!!!) to Compensate!
'If, in this process, we encounter
'a "WeekEnd" Day OR an additional HOLLIDAY,
'Don't Count it
MyHoliDay = FinishDt
For Idx = 1 To DaysToAdd
'TestDate for Holiday/Weekend day
MyHoliDay = DateAdd("d", DateDir, MyHoliDay)
'Check For Sat., Sun., And MyHoliDay
strSQL = "SELECT Count(tblHolidays.HoliDate) AS NumHoliD "
strSQL = strSQL & "FROM tblHolidays "
strSQL = strSQL & "GROUP BY tblHolidays.HoliDate "
strSQL = strSQL & "HAVING (((tblHolidays.HoliDate) = "
strSQL = strSQL & Chr(35) & MyHoliDay & Chr(35) & "));"
qdf.SQL = strSQL
Set rst = dbs.OpenRecordset("qryNumHolidayIncl", dbOpenDynaset)
If (Not (rst.BOF) Or Not (rst.EOF)) Then
MyDOW = Choose(WeekDay(MyHoliDay), 1, 2, 3, 4, 5, 6, 7)
If (MyDOW <> 1 And MyDOW <> 7) Then
DaysToAdd = DaysToAdd + rst!NumHoliD
End If
End If
Next Idx
basWeekdays = DateAdd("d", DaysToAdd, FinishDt)
End Function
HoliDate Holiday
1/1/00 New Years Day
1/17/00 Martin Luther King Day
2/2/00 Groundhog Day
2/12/00 Lincon's Birthday
2/14/00 President's Day
2/21/00 Valentine's Day
2/22/00 Washington's Birthday
3/8/00 Ash Wednesday
3/17/00 St. Patrick's Day
4/1/00 April Fool's Day
4/20/00 Passover
4/21/00 Good Friday
5/5/00 Cinco de Mayo
5/5/00 Cinco de Mayo
5/14/00 Mother's Day
6/11/00 Pentecost
6/18/00 Father's Day
7/4/00 Independence Day
9/4/00 Labor Day
10/31/00 Halloween
11/11/00 tran's Day
11/23/00 Thanksgiving
12/25/00 Christmas
12/31/00 New Year's Eve
1/1/01 New Years Day
1/17/01 Martin Luther King Day
2/2/01 Groundhog Day
2/12/01 Lincon's Birthday
2/14/01 President's Day
2/21/01 Valentine's Day
2/22/01 Washington's Birthday
3/8/01 Ash Wednesday
3/17/01 St. Patrick's Day
4/1/01 April Fool's Day
4/20/01 Passover
4/21/01 Good Friday
5/14/01 Mother's Day
6/11/01 Pentecost
6/18/01 Father's Day
7/4/01 Independence Day
9/4/01 Labor Day
10/31/01 Halloween
11/11/01 tran's Day
11/23/01 Thanksgiving
12/25/01 Christmas
12/31/01 New Year's Eve
1/1/02 New Years Day
1/17/02 Martin Luther King Day
2/2/02 Groundhog Day
2/12/02 Lincon's Birthday
2/14/02 President's Day
2/21/02 Valentine's Day
2/22/02 Washington's Birthday
3/8/02 Ash Wednesday
3/17/02 St. Patrick's Day
4/1/02 April Fool's Day
4/20/02 Passover
4/21/02 Good Friday
5/5/02 Cinco de Mayo
5/14/02 Mother's Day
6/11/02 Pentecost
6/18/02 Father's Day
7/4/02 Independence Day
9/4/02 Labor Day
10/31/02 Halloween
11/11/02 tran's Day
11/23/02 Thanksgiving
12/25/02 Christmas
12/31/02 New Year's Eve