G
Guest
The following code returns an integer. However every time I try to filter on
the record using a whole number the I get a data type mismatch
Option Compare Database
Public Function WorkingDays3(StartDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays3
' 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_WorkingDays3
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
If intCount > 4 Then
WorkingDays3 = intCount
End If
Exit_WorkingDays3:
Exit Function
Err_WorkingDays3:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays3
End Select
End Function
'*********** Code End **************
the record using a whole number the I get a data type mismatch
Option Compare Database
Public Function WorkingDays3(StartDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays3
' 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_WorkingDays3
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
If intCount > 4 Then
WorkingDays3 = intCount
End If
Exit_WorkingDays3:
Exit Function
Err_WorkingDays3:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays3
End Select
End Function
'*********** Code End **************