SQL Data Type Mismatch

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hype261
    New Member
    • Apr 2010
    • 207

    #1

    SQL Data Type Mismatch

    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...

    Code:
    SELECT Count(*) AS NumTests, ConvertDate(IssuedDate)
    FROM ItasWithCancelledTests
    GROUP BY ConvertDate(IssuedDate);
    Here is my Function Convert Date

    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
    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.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Nothing jumps out at me as being wrong. Have you tried stepping through the code?

    Comment

    • hype261
      New Member
      • Apr 2010
      • 207

      #3
      I just figured it out. I had used the function before it a different app so I was pretty sure it worked. The difference between the two was that in my other app the date field was marked as required where in this one the date field is not marked as required. This allowed Access to mark my Date as a Nullable Date where my function is looking for a Non Null Date.

      Comment

      Working...