iwieldthehammer
New member
- Local time
- Yesterday, 22:56
- Joined
- Dec 28, 2017
- Messages
- 5
I have a database that I am building a query form for. This database contains thousands of products offered by hundreds of specialty food companies – my intent is to design a form enables the user to select three key words that relate to their product interest (such as ‘cheese’, ‘mild’ and ‘cheddar) as well as any number of geographic regions in which the user is looking for products. The form looks basically like the below:
What are three keywords which relate to the products you are interested in?
Keyword 1 _____
Keyword 2 _____
Keyword 3 _____
What geographic regions are you looking for products from:
__ New England
__ Mid-Atlantic
The goal here is that the user types in up to three words and then selects any number of geographic regions. My problem is, I cannot get the OR statements to work in the query. In other words, I can only get it to select records if I choose one (and ONLY one) geographic region, using the query below (I just have two regions in there for now, New England and Mid-Atlantic):
SELECT Product.[Booth #], Product.Company, Product.State, Product.Country, Product.Phone, Product.Website, Product.[Product Name]
FROM Product
WHERE (((Product.[Booth #])<>"0")
AND
((Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword1] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword2] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword3] & "*"))
AND
(
((Product.[New England (CT, ME, MA, NH, RI, VT)]) Like IIf([forms]![SearchF]![New England]=-1,[forms]![SearchF]![New England],"*"))
AND
((Product.[Mid-Atlantic (NJ, NY, PA)]) Like IIf([forms]![SearchF]![Mid-Atlantic]=-1,[forms]![SearchF]![Mid-Atlantic],"*"))
);
If I try replacing the last AND in the above query (the one between the geographic regions of New England and Mid-Atlantic) with an OR, as below, the query will ignore the geographic selections unless I select ALL of the options (in this case both New England and Mid-Atlantic checkboxes):
SELECT Product.[Booth #], Product.Company, Product.State, Product.Country, Product.Phone, Product.Website, Product.[Product Name]
FROM Product
WHERE (((Product.[Booth #])<>"0")
AND
((Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword1] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword2] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword3] & "*"))
AND
(
((Product.[New England (CT, ME, MA, NH, RI, VT)]) Like IIf([forms]![SearchF]![New England]=-1,[forms]![SearchF]![New England],"*"))
OR
((Product.[Mid-Atlantic (NJ, NY, PA)]) Like IIf([forms]![SearchF]![Mid-Atlantic]=-1,[forms]![SearchF]![Mid-Atlantic],"*"))
);
I would appreciate some help with this. I would like the query to take the first two clauses in the WHERE statement (which work fine) and then, if the user selects a geographic region, add in that criteria. Is it the Like IIf statement that is causing the issue? If so, what are the alternatives to making the checkboxes work?
Thanks!
What are three keywords which relate to the products you are interested in?
Keyword 1 _____
Keyword 2 _____
Keyword 3 _____
What geographic regions are you looking for products from:
__ New England
__ Mid-Atlantic
The goal here is that the user types in up to three words and then selects any number of geographic regions. My problem is, I cannot get the OR statements to work in the query. In other words, I can only get it to select records if I choose one (and ONLY one) geographic region, using the query below (I just have two regions in there for now, New England and Mid-Atlantic):
SELECT Product.[Booth #], Product.Company, Product.State, Product.Country, Product.Phone, Product.Website, Product.[Product Name]
FROM Product
WHERE (((Product.[Booth #])<>"0")
AND
((Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword1] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword2] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword3] & "*"))
AND
(
((Product.[New England (CT, ME, MA, NH, RI, VT)]) Like IIf([forms]![SearchF]![New England]=-1,[forms]![SearchF]![New England],"*"))
AND
((Product.[Mid-Atlantic (NJ, NY, PA)]) Like IIf([forms]![SearchF]![Mid-Atlantic]=-1,[forms]![SearchF]![Mid-Atlantic],"*"))
);
If I try replacing the last AND in the above query (the one between the geographic regions of New England and Mid-Atlantic) with an OR, as below, the query will ignore the geographic selections unless I select ALL of the options (in this case both New England and Mid-Atlantic checkboxes):
SELECT Product.[Booth #], Product.Company, Product.State, Product.Country, Product.Phone, Product.Website, Product.[Product Name]
FROM Product
WHERE (((Product.[Booth #])<>"0")
AND
((Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword1] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword2] & "*" And (Product.CustomColumn1description) Like "*" & [Forms]![SearchF]![Keyword3] & "*"))
AND
(
((Product.[New England (CT, ME, MA, NH, RI, VT)]) Like IIf([forms]![SearchF]![New England]=-1,[forms]![SearchF]![New England],"*"))
OR
((Product.[Mid-Atlantic (NJ, NY, PA)]) Like IIf([forms]![SearchF]![Mid-Atlantic]=-1,[forms]![SearchF]![Mid-Atlantic],"*"))
);
I would appreciate some help with this. I would like the query to take the first two clauses in the WHERE statement (which work fine) and then, if the user selects a geographic region, add in that criteria. Is it the Like IIf statement that is causing the issue? If so, what are the alternatives to making the checkboxes work?
Thanks!