data type mismatch error 3464

D

dhawkins

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 **************
 
C

ChrisJ

I suspect you problem is the line

rst.FindFirst "[HolidayDate] = #" & StartDate & "#"

Try changing it to
rst.FindFirst "[HolidayDate] = #" & format$(StartDate, "mmm dd yyyy") & "#"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

#Error in Results 5
How to use a function in a query 1
Holiday day tracking 2
weekends and holidays! 5
Help modifying a "working days" query/function 4
Workdays Function 0
Custom Function 6
Holiday - Error 4

Top