Using InStr or Like in a query

MCTampa

Board Regular
Joined
Apr 14, 2016
Messages
97
Resort Codes
Resort Searches
MM1
HNS;HSL;MG1;MG3;MG5;MGA;MM1;WNL
GTR
HNS;GTR;MG1;MG3;MG5;MGA;MML;WNL
NCV
HNS;HSL;MG1;MG3;MG5;MGA;MML;WNL
MKO
HNS;HSL;MG1;MG3;MG5;MGA;MKO;WNL

<tbody>
</tbody>
Hello,

I have a table with two columns: list of resort codes and a list of resort searches.
I would like to create query in which Access evaluates whether or not a resort code is found in the corresponding search list.
I am trying to use the Like method, but it only seems to work when there is just one resort in the search field and it happen to be a match.

Any ideas?

Thanks
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Use Query Criteria like this:
Code:
Like "*MML*"
 
Upvote 0
Yes, but then I have to specify the resort code I want to search for each time.
I want access to evaluate each row and only bring back the rows where the resortID is present in the resort search field

I'm trying to use something like

Like [Output Test]![Resort ID] & '*'
or
Like '*[Output Test]![Resort ID]*'

The former only returns matches when there is one resort in the search criteria.
 
Last edited:
Upvote 0
OK. I misunderstood what you were asking, but think I see what you are trying to do now.
Add this field to your Query (which you can elect to not display, if you like):
Code:
x: InStr([Resort Searches],[Resort Codes])>0
Then, in the Criteria of this field, add this:
Code:
True

I think that will do what you want, which is return all records where the Resort Code from that record exists in the Resort Searches in that same record.
 
Last edited:
Upvote 0
Construct the search as HNS,HSL etc and the use the IN clause
Rich (BB code):
WHERE ResortCode IN (HNS,HSL,MG1,MG3,MG5,MGA,MM1,WNL)

HTH
 
Upvote 0
Construct the search as HNS,HSL etc and the use the IN clause
Rich (BB code):
WHERE ResortCode IN (HNS,HSL,MG1,MG3,MG5,MGA,MM1,WNL)

HTH

What I want to write is something like Where [Alert Details]![Resort Codes] In ([Alert Details]![Rental Alert ID]) so I don't have to specify the resort codes I'm searching for. But I cannot get it to work.
 
Upvote 0
What I want to write is something like Where [Alert Details]![Resort Codes] In ([Alert Details]![Rental Alert ID]) so I don't have to specify the resort codes I'm searching for. But I cannot get it to work.
Did you miss my last reply?
I showed you how to do that, once I saw what you were after.
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top