G
Guest
I have attempted to use the second function here:
http://www.mvps.org/access/datetime/date0006.htm
________________________________________________________________
Public Function WorkingDays2(StartDate As Date, EndDate As Date) As Integer
On Error GoTo Err_WorkingDays2
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
WorkingDays2 = intCount
Exit_WorkingDays2:
Exit Function
Err_WorkingDays2:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select
End Function
________________________________________________________________
I have created a table called "tblholidays" and entered two dates for two
public holidays in "holidaydate" being 06/04/2007 and 09/04/2007
In the query I have inserted the following:
DaysW1: WorkingDays2([SLA_Date1],[SLA_Date2])
For one row the two dates are 05/04/2007 and 10/04/2007
For this row I thought DaysW1 should equal 2 but it doesn't. It equals 4.
This suggests it is ignoring the weekend (7th and 8th) but not the public
holidays (6th and 9th)
A) Can anyone say why it is not ignoring the public holidays?
B) I don't want the total number of days. I want the difference so the
answer to the above should be 1.
cheers!
http://www.mvps.org/access/datetime/date0006.htm
________________________________________________________________
Public Function WorkingDays2(StartDate As Date, EndDate As Date) As Integer
On Error GoTo Err_WorkingDays2
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
WorkingDays2 = intCount
Exit_WorkingDays2:
Exit Function
Err_WorkingDays2:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select
End Function
________________________________________________________________
I have created a table called "tblholidays" and entered two dates for two
public holidays in "holidaydate" being 06/04/2007 and 09/04/2007
In the query I have inserted the following:
DaysW1: WorkingDays2([SLA_Date1],[SLA_Date2])
For one row the two dates are 05/04/2007 and 10/04/2007
For this row I thought DaysW1 should equal 2 but it doesn't. It equals 4.
This suggests it is ignoring the weekend (7th and 8th) but not the public
holidays (6th and 9th)
A) Can anyone say why it is not ignoring the public holidays?
B) I don't want the total number of days. I want the difference so the
answer to the above should be 1.
cheers!