So I have a SQL Query I am trying to author and it keeps giving me a Data Type mismatch error which I can't seem to see. Exact error message is Data type mismatch in criteria expression.
Here is the SQL...
Here is my Function Convert Date
I have verified that the field IssuedDate is a Date field and if I take away the User designed function then it works properly. Anybody see a problem in my logic here.
Here is the SQL...
Code:
SELECT Count(*) AS NumTests, ConvertDate(IssuedDate) FROM ItasWithCancelledTests GROUP BY ConvertDate(IssuedDate);
Code:
'This method converts a date into a required format
'valid items for the format are:
'Day for day
'Week for week
'Month for month
'Year for year
Public Function ConvertDate(dt As Date) As Date
On Error GoTo Err_ConvertDate
Dim format As String
'If the person hasn't entered a dateFilter set it to Day
format = Nz(TempVars("dateFilter"), "Day")
Select Case format
Case "Day"
ConvertDate = dt
Case "Week"
ConvertDate = DateAdd("ww", DatePart("ww", dt, , vbFirstJan1) - 2, DateSerial(DatePart("yyyy", dt), 1, 1))
Case "Month"
ConvertDate = DateSerial(DatePart("yyyy", dt), DatePart("m", dt), 1)
Case "Year"
ConvertDate = DateSerial(DatePart("yyyy", dt), 1, 1)
Case Default
ConvertDate = Date
MsgBox "Unable to recognize format"
End Select
Exit_ConvertDate:
Exit Function
Err_ConvertDate:
MsgBox Err.Description
Resume Exit_ConvertDate
End Function
Comment