S
scott04
Hi everyone I am trying to calculate a date difference excluding holidays. I
have a tbl in the database name tblholidays with a HolidayDate Field in the
table. I have a textbox in my report with the control source
=(WorkingDays2([Sdate],[Completed_by_date]))
My module is the following
Public Function Workingdays2(SDate As Date, Completed_by_date 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)
intCount = 0
Do While SDate <= Completed_by_date
rst.FindFirst "[HolidayDate] = #" & SDate & "#"
If Weekday(SDate) <> vbSunday And Weekday(SDate) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
SDate = SDate + 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
Can someone please see if i have done something wrong as it is not looking
at the dates i input in my tblHolidays table?? Example i have 12/31/2008 as
SDate and 1/13/2009 as Completed_by_date but result = 10 when i have
1/1/2009 as a holiday. Thanks.
have a tbl in the database name tblholidays with a HolidayDate Field in the
table. I have a textbox in my report with the control source
=(WorkingDays2([Sdate],[Completed_by_date]))
My module is the following
Public Function Workingdays2(SDate As Date, Completed_by_date 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)
intCount = 0
Do While SDate <= Completed_by_date
rst.FindFirst "[HolidayDate] = #" & SDate & "#"
If Weekday(SDate) <> vbSunday And Weekday(SDate) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
SDate = SDate + 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
Can someone please see if i have done something wrong as it is not looking
at the dates i input in my tblHolidays table?? Example i have 12/31/2008 as
SDate and 1/13/2009 as Completed_by_date but result = 10 when i have
1/1/2009 as a holiday. Thanks.