Results 1 to 5 of 5
  1. #1
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108

    Error 3464 (Data type mismatch in criteria expression) with OpenRecordset

    This is driving me nuts. I have a table with a lot of entries. All the fields are strings (ShortText).

    I perform the following
    Code:
    wSQL = "SELECT STNumbers.* FROM STNumbers WHERE STNumbers.STN_Class =""" & wClass & """ ORDER BY VAL(STNumbers.STN_N02) ASC;"
    Set rs = CurrentDb.OpenRecordset(wSQL, DB_OPEN_DYNASET)
    wClass is atring. And this code works almost everytime for many values I place in wClass. But if I put "LN:A2" I get this error 3464.

    I have made sure that every record with this field (STN_Class = LN:A2) has valid string data - but no matter how I try and cleanse this data it always fails - just for this value - all other values work????

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Are you sure it's not failing on a record with Null in the field? Only takes one.
    FWIW I use " ' " (spaced for clarity) not """ thus don't have to worry about when it works and when it doesn't.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,936
    Works for me, in that I have no data to match that criteria on first test?
    Works when I add a record to match that criteria.
    Works when I have a Null in that criteria field?

    SELECT * FROM tblProducts WHERE tblProducts.Product ="LN:A2" ORDER BY VAL(IDProduct) ASC;
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    SELECT * FROM tblProducts WHERE tblProducts.Product ="LN:A2" ORDER BY VAL(IDProduct) ASC;
    I don't see that as being the same thing. Methinks that as posted, with null being passed to the variable, you'd be using a zls as criteria (""). However, after reconsidering, this is a SELECT sql statement, which means zls should not be an issue. I'm now thinking that the problem is about what's being passed to the Val function. If using an error trap, code can be halted when it errs and the value of VAL(STNumbers.STN_N02) can be examined. A string with no numbers should return zero (0). Val(Null) should raise an error.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    For the records with STN_Class = LN:A2 make sure the STNumbers.STN_N02 field is also valid (as the error might come from the Val() function).
    EDIT: Micron said it first
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 1
    Last Post: 10-08-2020, 07:48 PM
  2. Replies: 3
    Last Post: 12-10-2019, 07:04 PM
  3. Replies: 4
    Last Post: 07-25-2019, 05:49 PM
  4. Replies: 8
    Last Post: 03-14-2017, 02:36 PM
  5. Replies: 2
    Last Post: 08-24-2015, 09:14 PM

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