Bruno Adriano
Bruno Adriano

Reputation: 3

MS ACCESS - Query Criteria based on two Textbox

I need to make a search box that could reach and take any field, since I know about nothing of VBA, I did it by using queries...

I have a query with this OR criteria in each field (properly done in there):

Like "*" & [txtbox1] & "*" Or Like "*" & [txtbox2] & "*"

Problem is: it's not working as intended...

If I type nothing on either box1 or box2, it shows all... even when, say, I type something I know is on one field and in the other something from another field then it shows still a lot it shouldn't show...

I wanted it to filter by the first, and then that results by the other one... only show result that meet both criteria (when I type in both txtboxes)

Upvotes: 0

Views: 563

Answers (1)

Hedinn
Hedinn

Reputation: 864

if it needs to match both textbox1 and textbox2 you should use an AND instead of the OR

Like "*" & [txtbox1] & "*" And Like "*" & [txtbox2] & "*"

Ok, based on your comment I'm guessing you are using the query designer, I'm not sure how this can be done using the desginer, this can be done using SQL so a basic query

SELECT *
FROM TABLE
WHERE (field1 like "*" & [txtbox1] & "*" OR field2 like "*" & [txtbox1] & "*" ....for all the required columns) 
AND (field1 like "*" & [txtbox2] & "*" OR field2 like "*" & [txtbox2] & "*" ....for all the required columns)

Upvotes: 0

Related Questions