Results 1 to 5 of 5
  1. #1
    FrankAccess is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    3

    Please help: AND OR Criteria in Query cause Criteria separation

    Hello,

    I am in the middle of creating a query which pulls results from a large table based on the checkboxes that are found in a form. For instance, when I check off a checkbox called "Honda" on my form, my query will return all Table results that contain the word Honda. I made this work properly, however when I save and close the query, access splits up my criteria where I have an "AND" or an "OR" (presumably because it thinks these words are redundant, and that a column/row shift would suffice). You can what this looks like in the attached file. This doesn't create a problem in the sample database that I have created but in my actual database (over 200,000 entries), access cannot run the query once the criteria have been separated (the pre-save unseparated query version works fine).

    Is there a way to prevent access from separating my query criteria? For your reference, I have included the unseparated criteria at the bottom of this post.

    Thank you for your help.

    PLEASE NOTE: The form called "Search" must be open in order to successfully open any of the queries. To update any query results after selecting different checkboxes, either run the query again OR close the query and reopen it. Also, I have included three queries in this database so that you can see the make and color criteria acting together and in isolation.

    Criteria

    Color
    (([forms]![Search]![AnyColorCheck]=True) And (Is Not Null)) Or (([forms]![Search]![BlueCheck]=True) And "blue") Or (([forms]![Search]![redCheck]=True) And "red") Or (([forms]![Search]![orangeCheck]=True) And "orange") Or (([forms]![Search]![greenCheck]=True) And "green")



    Make
    (([forms]![Search]![AnymakeCheck]=True) And (Is Not Null)) Or ((forms![Search]![BMWCheck]=true) and "bmw") Or ((forms![Search]![mazdaCheck]=true) and "mazda") Or ((forms![Search]![porscheCheck]=true) and "porsche") Or ((forms![Search]![dodgeCheck]=true) and "dodge") Or ((forms![Search]![chevyCheck]=true) and "chevy") Or ((forms![Search]![hondaCheck]=true) and "honda") Or ((forms![Search]![mercedesCheck]=true) and "mercedes")
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    If you want to allow dynamic selection of multiple criteria for one field, really need VBA code to construct filter string and apply the filter to a form or report.

    Here's an example that allows selection of multiple items from a listbox http://allenbrowne.com/ser-50.html

    What you have with checkboxes gets event more complicated.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    FrankAccess is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    3
    Thanks June7. I will try to use VBA [need to learn it first).

  4. #4
    FrankAccess is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    3
    So I tried out the VBA approach and must say that it is way over my head. Is there another way that I can do this? I don't necessarily need to use checkboxes, a multi-select list box will work as well. I have looked at other threads that explained how to use a multi-select list box but was unable to get this to work for me. Would someone be kind enough to create a query that gets its parameters from a multi-select listbox?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    The VBA example demonstrated in that link is the only way. If you Google 'access vba multi-select listbox filter' most hits will lead you back to Allen Browne's code or something along the same lines. Here is a thread discussing the issue and has a db attached you might find helpful http://www.access-programmers.co.uk/...d.php?t=215560
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-20-2012, 03:27 PM
  2. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  3. Replies: 1
    Last Post: 07-13-2011, 11:00 AM
  4. Replies: 1
    Last Post: 06-12-2011, 07:08 AM
  5. Search By Criteria - Flexible Criteria Fields
    By lilanngel in forum Access
    Replies: 0
    Last Post: 03-16-2011, 06:25 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