We help IT Professionals succeed at work.

Complicated search function

SteveL13
SteveL13 asked
on
60 Views
Last Modified: 2019-01-26
I have a form that has 5 comboboxes on it.  They are named cboCriteria1, cboCriteria2, cboCriteria3, cboCriteria4, and cboCriteria5,

And I have a table that looks like this:
 TableExample
If the user selects "Football" in any one of the 5 comboboxes I want the records that have "Football" entered in any of the 5 criteria fields in the table to be displayed in a form that opens in datasheet view mode.  Or in this case, records 1 and 6.  And f the user selects "Football" in all 5 comboboxes then I want the same result...  records 1 and 6 to be displayed.

But if the user for example selects "Football" in the 3rd combobox and "Baseball" in the 2nd combobox then I want all of the field data in records 1, 5, and 6 to display.

The resulting form should display all data in each of the records that have been found.  The form will open as a result of a click of a command button.
Comment
Watch Question

Daniel PineaultPresident / Owner CARDA Consultants Inc.
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
You're going to have to use VBA I suspect to first count the number of combo boxes used for the search and then build the appropriate WHERE clause.

As a side note, your table structure should not be horizontal in this manner, but instead vertical, such as

RecordId
Criteria
CriteriaType
...
Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

Commented:
Your going to have a tough time with this because the table design is not good.

 At the moment, your going to be stuck with using VBA and walking the records to figure out which should be included, or building a temp table, executing multiple append queries to check each column.   Then basing the form on a query with a SELECT DISTINCT so you get one row per.

 You really should change the design before you go further.

Jim.
Dale FyeOwner, Dev-Soln LLC
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010

Commented:
I would agree with Jim that your table design leaves something to be desired.

However, you could create a where clause that looks something like:

WHERE instr([Criteria1] & "," & [Criteria2] & "," & [Criteria3] & "," & [Criteria4] & "," & [Criteria5], NZ(Forms!yourForm!cboCriteria1,"")) >0
OR instr([Criteria1] & "," & [Criteria2] & "," & [Criteria3] & "," & [Criteria4] & "," & [Criteria5], NZ(Forms!yourForm!cboCriteria2,"")) >0
...

Another method would be to replace the combo boxes with a multi select list and build a string from the items selected in the list (would require VBA) and in that case, the SQL would look something like:

WHERE [Critieria1] IN ("Football", "Baseball")
OR [Criteria2] IN ("Football", "Baseball")
...

Author

Commented:
Too all..  Thank you so far.  I have attached a mock-up database with data entered that may help someone figure out an answer,  Note that I did re-work the initial table.

SearchMockup.accdb
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.