• data type mismatch error on date/time value (access 2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » data type mismatch error on date/time value (access 2003)

    Author
    Topic
    #454042

    When I run this SQL I’m getting a Data type mismatch error. I’m at a lose as to why. The table adminsum stores the appointment date as a text value. I’m trying to convert this to a date/time value in my query. Any thoughts why I’m getting this error? When I remove the group by on the admin date field the error goes away but I want to group by the different dates. Thanks..

    SELECT AdminSum.[Admin ID], Count(AdminSum.[CBSR Appointment ID]) AS [CountOfCBSR Appointment ID], AdminSum.[Site ID], CLng(Nz([Appointment Date])) AS AdminDate
    FROM AdminSum
    WHERE (((AdminSum.[Event Outcome]) Not Like “Candidate No-Show”))
    GROUP BY AdminSum.[Admin ID], AdminSum.[Site ID], CLng(Nz([Appointment Date]))
    HAVING (((AdminSum.[Admin ID]) Not Like “2007*”));

    Viewing 2 reply threads
    Author
    Replies
    • #1126077

      What type of field is [Admin ID] ? Is it a Text field? Using Like with an ID field looks odd, but may be ok.

      Does CLng work with your Appointment Dates?
      Why don’t you use CDate?

    • #1126084

      What happens if you change both occurrences of

      CLng(Nz([Appointment Date]))

      to

      CDate(Nz([Appointment Date],#01/01/1900#))

      You can replace #01/01/1900# with whatever date you would want to use instead of a blank.

      • #1126096

        Tried it but I still get the same error. It runs and then fails. It’s only when I do a group by statement or add any kind of parameter. If I don’t group by any feilds or andd amy parameters it runs and converts the format to a date/time value. I set the properties of the field in the query to date/time value..

        SELECT AdminSum.[Admin ID], Count(AdminSum.[CBSR Appointment ID]) AS [CountOfCBSR Appointment ID], AdminSum.[Site ID], CDate(Nz([Appointment Date],#1/1/1900#)) AS AdminDate
        FROM AdminSum
        WHERE (((AdminSum.[Event Outcome]) Not Like “Candidate No-Show”))
        GROUP BY AdminSum.[Admin ID], AdminSum.[Site ID], CDate(Nz([Appointment Date],#1/1/1900#));

        • #1126102

          Does the Appointment Date field contain values that cannot be converted to a date? Create a ‘normal’ query that adds the AdminDate field, and look for records that show #Error or similar in the AdminDate column.

          • #1126110

            That was it Hans. I had some goofy dates in there. Once I got them out it ran ok..

    • #1126086

      Why are you using CLng to convert [Appointment Date] to a Date field? Use CDate()!

    Viewing 2 reply threads
    Reply To: data type mismatch error on date/time value (access 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: