C
Coach K
I have a query that calculates dates using the WorkingDays2 function. If one
of the fields does not have a date yet i get the #error in the record. What
do i need to add to make it a null value?
Here is the code:
Public Function WorkingDays2(startdate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays2
' 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
And big thank you to Arvin Meyer for the code.
Thanks for your help in advance.
of the fields does not have a date yet i get the #error in the record. What
do i need to add to make it a null value?
Here is the code:
Public Function WorkingDays2(startdate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays2
' 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
And big thank you to Arvin Meyer for the code.
Thanks for your help in advance.