Results 1 to 9 of 9
  1. #1
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83

    Data type mismatch in query

    Could someone please look at the below module and query and tell me if you know why I am getting a data type mismatch error when running?
    Both fields in the table are "Text" so I don't get why it's doing this. Found this code on another site.

    Module
    Public Function Concat(strDEV_CD As String, _
    strConstraint As String) As String
    Static strLastDEV_CD As String
    Static strConstraints As String



    If strDEV_CD = strLastDEV_CD Then
    strConstraints = strConstraints & ", " & strConstraint
    Else
    strLastDEV_CD = strDEV_CD
    strConstraints = strConstraint
    End If
    Concat = strConstraints
    End Function

    Query
    SELECT DEV_CD, Max(Concat(DEV_CD,MAN_CON_DESC)) AS Constraints
    FROM [Copy Of q_Combined]
    GROUP BY DEV_CD;

    Thanks!

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I did not see any problem.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Could either value be Null?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    and...what light is breaking?

  5. #5
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    yes, there will be null values in MAN_CON_DESC field.

    Apparently I need to account for that in my query?

    Thanks

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Or in the function. This:

    strConstraint As String

    can only accept a String; it will error if a Null is passed to it. Only a Variant can accept a Null. So either you modify the function to handle Nulls or use the Nz() function in the query call to pass something other than Null to the function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    Don't know what I'm doing wrong but I'm getting an error message "Reserved error (-1038) there is no message for this error", when changing the query to read:

    Man: Max(Concat(Nz([DEV_CD],"Null"),Nz([MAN_CON_DESC],"Null ")))

    I've also tried
    Man: Max(Concat([DEV_CD],Nz([MAN_CON_DESC],"Null"))

    Same error

    Thanks,

    Toni

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Have you set a breakpoint to see if it's getting through the function correctly?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by pbaldy View Post
    Have you set a breakpoint to see if it's getting through the function correctly?
    either that, or press F8 to run it line by line. If you'd like some quick tips on how to use the editor's debugging tools, have a look here: http://www.ajenterprisesonline.com/ab/_vbe/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. data type mismatch in criteria expression
    By broecher in forum Access
    Replies: 4
    Last Post: 09-10-2010, 08:29 AM
  2. Data type mismatch in criteria expression
    By shexe in forum Queries
    Replies: 2
    Last Post: 09-01-2010, 12:47 PM
  3. Type mismatch
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 08-07-2010, 06:54 AM
  4. data type mismatch
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 08-02-2010, 04:15 PM
  5. Type mismatch in expression /Query
    By Brian62 in forum Queries
    Replies: 4
    Last Post: 04-22-2010, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums