Results 1 to 9 of 9
  1. #1
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109

    Select query with condition date later or equl to

    Hi Guys,

    actually quite simple question but I can't get it working. Why below doesn't work?

    Code:
    CurrentDb.OpenRecordset("SELECT * FROM tbMessage WHERE messageType = 2 AND expirationDate <= #12/18/2014#")
    It says error and I don't know why... messageType and expriationDate are fields in table "tbMessage".

    Robert

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Looks fine. What's the text of the error? Presumably you're setting a recordset variable?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    It's error 3464: Data type mismatch in criteria expression. What's interesting, I get the error only when resulting recordset wouldn't be empty. For instance, assuming there's only 1 record in "tbMessage" table of expirationDate = today's date. In this case the expresion:
    Code:
    CurrentDb.OpenRecordset("SELECT * FROM tbMessage WHERE messageType = 2 AND expirationDate <= #12/18/2014#")
    wouldn't result in empty recordset hence there would be the error. If I changed it to:
    Code:
    "..expirationDate = #12/18/2014#")
    or
    Code:
    "..expirationDate >= #12/18/2014#"
    no error would be produced and it'd performed correctly. Don't really get it.

    I think it might have something to do with date format. In sql it's american so mm/dd/yyyy, in the table it's dd-mm-yyyy though i'm not sure if it's not only the way it's displayed there.

    Robert

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If messagetype is text it would be:

    CurrentDb.OpenRecordset("SELECT * FROM tbMessage WHERE messageType = '2' AND expirationDate <= #12/18/2014#")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Unfortunately not, messageType is long integer.

  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
    What's the actual code? You're saying it works correctly with just the date criteria? Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Can't believe but messageType was in fact set as Text.. gotta start to pay more attention to what I do. Sorry for this topic, embarrassing really.

    Robert

  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
    No worries, we've all done it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    kemas is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    6
    Code:
    CurrentDb.OpenRecordset("SELECT * FROM tbMessage WHERE [messageType] = 2 AND [expirationDate] <= #12/18/2014#")

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

Similar Threads

  1. Query: select latest date within given category
    By martinhough in forum Queries
    Replies: 4
    Last Post: 10-22-2013, 12:34 PM
  2. Replies: 1
    Last Post: 05-09-2013, 09:13 AM
  3. Create a query to select a date
    By orcaa in forum Queries
    Replies: 1
    Last Post: 12-30-2012, 08:35 PM
  4. Using form combo box in query to select date.
    By LordNecro in forum Access
    Replies: 2
    Last Post: 04-14-2012, 05:09 AM
  5. Select Query Using Different Date Ranges
    By Hemi426 in forum Queries
    Replies: 3
    Last Post: 07-26-2010, 01:06 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