Question : Data Type Mismatch in Criteria Expression - Using DateDiff function

I have the code below and am getting the mismatch error.  Should I be wrapping the DateDiff function, or something?  I don't understand why I'm getting the error.  Thank you.

Public Function GPCEffDateDiff(TypeIn As String)        
Dim rst As DAO.Recordset
Dim sqlGPCEffDateDiff As String
Dim countDays As Integer
Dim strSQL As String

'Number of Days between Original Effective Date and Policy Change Effective Date
sqlGPCEffDateDiff = "SELECT OrigEffDate, PolChgEffDate, DateDiff('d', OrigEffDate, PolChgEffDate) As EffDaysDifference, * From qry_FilteredRecords_GPC WHERE Nz(DateDiff('d', OrigEffDate, PolChgEffDate), 0) <= 90"

strSQL = sqlGPCEffDateDiff
If TypeIn = "ShowRecords" Then
    showRecords strSQL
    Else
    Set rst = CurrentDb.OpenRecordset(sqlGPCEffDateDiff)<--------------------RIGHT HERE
        If rst.EOF Then
            countDays = 0
        Else
            ' The recordset was not empty
            rst.MoveLast
            countDays = rst.RecordCount
        End If
    Me!txtNoOfDays.Value = countDays
End If
End Function

Answer : Data Type Mismatch in Criteria Expression - Using DateDiff function

Data Type Mismatch = You tried to compare an apple to an orange.

sqlGPCEffDateDiff = "SELECT OrigEffDate, PolChgEffDate, DateDiff('d', OrigEffDate, PolChgEffDate) As EffDaysDifference, * From qry_FilteredRecords_GPC WHERE Nz(DateDiff('d', OrigEffDate, PolChgEffDate), 0) <= 90"

For example, if either OrigEffDate or PolChgEffDate contained a NULL value, or 'BANANA', or 42, it would throw an error, as DateDiff specifies that you have to feed those parameters Date values.
Random Solutions  
 
programming4us programming4us