GetBusinessDay is a function I wrote 5 or 6 years ago that adds them. Last
year I modified it so that it will also subtract them as well as add them.
You can get the code here:
http://www.datastrat.com/Code/GetBusinessDay.txt
The following code, written earlier and also modified for an app last year
does exactly what you are asking:
Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays
' Inputs: StartDate As Date
' EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date: February 19, 1997
' Modified to allow for holidays May 5,2002
' Comment: Accepts two dates and returns the number of weekdays between
them
'....................................................................
On Error GoTo Err_WorkingDays
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)
'StartDate = StartDate + 1
'To count StartDate as the 1st day comment out the line above
intCount = 0
Do While StartDate <= EndDate
rst.FindFirst "[HolidayDate] = #" & StartDate & "#"
If Weekday(StartDate) <> vbSunday And Weekday(StartDate) <> vbSaturday
Then
If rst.NoMatch Then intCount = intCount + 1
End If
StartDate = StartDate + 1
Loop
WorkingDays = intCount
Exit_WorkingDays:
Exit Function
Err_WorkingDays:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays
End Select
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
Les said:
I have a table which contains all the bank holidays for the year.
I also have a form which has two date entries numStartDate and
numEndDate.
I need to be able to count how many Bank Holidays are in between these dates
and show the number in the form in field numBankHolidays
I assume I need a Loop statment but I can't make it work.
The table and field names are tblBank_Holiday_Dates numHolidayDates
Thanks
Les