Results 1 to 7 of 7
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    Using "IN" in a query

    All, using Access 2010. I've been trying to use the IN clause in a query and not returning any results. I have a ID Code field that contains a State: "RepNJ" or "TamCA" etc. but when I try to use the IN I don't get results unless I put the whole ID Code Ex: IN("RepNJ","TamHI", "TamCA") I was trying to use a wildcard to return ID codes because there are so many. EX IN("Rep*","Tam*","CAP*") but this doesn't return any results. Can you not use a wildcard when trying to use "IN"??

  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,640
    My gut feeling is no. You need to use Like to use a wildcard, and an IN() clause converts to =. In other words:

    FieldName IN("RepNJ","TamHI", "TamCA")

    is the same as

    FieldName =
    "RepNJ" OR FieldName = "TamHI" OR FieldName = "TamCA"

    and a wildcard wouldn't be recognized in that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Ok. thanks

  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,640
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,360
    I was trying to use a wildcard to return ID codes because there are so many.
    Are there enough that you would entertain code? You could build a sql statement by looping through a recordset or an array and concatenating LIKE with OR
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

  7. #7
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I was trying to use a wildcard to return ID codes because there are so many. EX IN("Rep*","Tam*","CAP*") but this doesn't return any results. Can you not use a wildcard when trying to use "IN"??
    Depending on the nature of your data, and whether your example is truly indicative of the rest of your data, you might be able to do something like this:
    Code:
    WHERE Left(FieldName,3) IN ("Rep","Tam","CAP")

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

Similar Threads

  1. Replies: 4
    Last Post: 12-20-2015, 12:16 PM
  2. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  3. Replies: 1
    Last Post: 07-10-2015, 06:33 AM
  4. Replies: 1
    Last Post: 02-05-2015, 05:41 PM
  5. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08: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