B
Barb
I am trying to calculate the number of days between two dates taking into
consideration holidays and weekends. I am using the following code:
Public Function mdlWorkingDays2(StartDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: mdlWorkingDays2
' Inputs: StartDate As Date
' EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date: May 5,2002
' Comment: Accepts two dates and returns the number of weekdays between them
' Note that this function has been modified to account for holidays. It
requires a table
' named tblHolidays with a field named HolidayDate.
'....................................................................
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
'*********** Code End **************
I have aTable / Form called Recruitment and a Table called tblHolidays.
Within the Table/Form called Recruitment I have a StartDate field, an EndDate
field, and a Days field. I am entering the code as a module named
mdlWorkingDays2 in "Recruitment Database [mdlWorkingDays2 (Code)]. However, I
continue to get a #Name$ error in the Days field. In the ControlSource for my
Days field I have mdlWorkingDays2([StartDate],[EndDate]).
Any ideas what is wrong?
consideration holidays and weekends. I am using the following code:
Public Function mdlWorkingDays2(StartDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: mdlWorkingDays2
' Inputs: StartDate As Date
' EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date: May 5,2002
' Comment: Accepts two dates and returns the number of weekdays between them
' Note that this function has been modified to account for holidays. It
requires a table
' named tblHolidays with a field named HolidayDate.
'....................................................................
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
'*********** Code End **************
I have aTable / Form called Recruitment and a Table called tblHolidays.
Within the Table/Form called Recruitment I have a StartDate field, an EndDate
field, and a Days field. I am entering the code as a module named
mdlWorkingDays2 in "Recruitment Database [mdlWorkingDays2 (Code)]. However, I
continue to get a #Name$ error in the Days field. In the ControlSource for my
Days field I have mdlWorkingDays2([StartDate],[EndDate]).
Any ideas what is wrong?