Results 1 to 9 of 9
  1. #1
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273

    Query by more than one combo box

    I am trying to add a feature to a search form. Currently, the form opens a query based on the input from cboCourse1, displaying all of the employees that have passed a training course. The criteria under Course in the query is Like Forms!frmTrng!cboCourse1 & "*". I want to add a second combo box to search if anyone has had both of two different training courses. I tried Like Forms!frmTrng!cboCourse1 & "*" And Like Forms!frmTrng!cboCourse2 & "*" in the criteria, but get a blank datasheet. If it matters, cboCourse2 may be blank and may not be visible most of the time.


    How can I show both courses in the same query?

  2. #2
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    Use Or not And.

    If it can be blank add "*" & before the Forms! bit

    BUT, from your example it seems that the courses are all in the same field, so how is there more than one? Wouldn't they be in different fields, which means that you enter criteria sererately for each field.

  3. #3
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    cboCourse1 has a dropdown list of all courses available. cboCourse2 also has the same dropdown of those same courses, from the same source. The user may want to know which employees have had "How To Feed Animals Training" by selecting it in cboCourse1, and have also had "How Not To Get Bit While Feeding An Animal Training" by selecting it in cboCourse2. Shouldn't that make it an And statement in the query instead of an Or statement? They are trying to find out who has had both courses, not one or the other.
    In most cases, the user will only want to search by one training course at a time, so cboCourse2 will usually be blank.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    One way I have created search forms is to have the query for the search form return all records. Selecting an option from the combo box would set the form filter property (usually from a button press). If you wanted to add a 2nd selection from a combo box, the code would add the 2nd selection to the filter property.
    Involves some code, but more flexible (IMO).
    Have a 2nd button to clear the filter and display all records.

  5. #5
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    Of course I thought this might not be too difficult to do it through the query. Wrong again!

    If I put the criteria from the boxes on different lines of the query, thus making it an "Or" statement, this works fine, showing me a record of everyone who has had at least one of the courses selected. Can you explain why it doesn't work when I put the criteria on the same line separated with an "And"? Since I've come this far with it, I was hoping not to have to go back to the drawing board.

    Thank you for your time.

  6. #6
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    Something else I just noticed...
    I changed the query criteria back to the way I had it with the "And" separating the 2 comboboxes. With something in both boxes, I get a blank query returned, as I mentioned at the start. If something is in the first box but nothing in the second, it works as planned, showing results for the criteria passed to the query from the first combobox, as I also posted. I just tried it with nothing in the first box, but something in the second, and it is showing the correct records. That leads me to think that it is working, but there is something wrong with the syntax in the "And" part of it, if that makes sense.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Would you post the SQL of the query? Easier to see where you are at..

  8. #8
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    Ya know, I had an epiphany last night on why this isn't working...
    As an AND criteria, the query is trying to search for a record that has both training courses on the same record rather than gathering a recordset of both courses. Of course each record only holds one course. If I have one combobox blank and the other with an entry to search by, in either order, it works.
    What I may need to do is run 2 seperate queries, one for each combobox, then display the records where the employee name is in both recordsets. I haven't put much thought yet into how to go about doing this, but if I need any help, I know that help is only a keyboard away. Thanks for the help so far!

  9. #9
    shennin202 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    6
    Just a wild guess from a novice...
    What about using a subquery to select all employees who have the course in cbo1, with the outer query selecting those employees in the list who have taken the course in cbo2? Or vice-versa with the cbo's, not too sure what the sql would look like...

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

Similar Threads

  1. Using combo box for query value
    By yawalias in forum Queries
    Replies: 8
    Last Post: 06-04-2014, 12:15 PM
  2. combo box query based on different query result?
    By mejia.j88 in forum Queries
    Replies: 10
    Last Post: 02-15-2012, 02:00 PM
  3. Replies: 19
    Last Post: 08-25-2011, 10:54 AM
  4. Replies: 4
    Last Post: 08-16-2011, 05:54 PM
  5. Combo Box Query.
    By millerdav99 in forum Queries
    Replies: 4
    Last Post: 03-23-2011, 09:26 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