Query Keywords from a Keyword Table

brncao

Board Regular
Joined
Apr 28, 2015
Messages
134
In the Criteria field, I would like to avoid the "Or Like" redundancy and would prefer to use a table of keywords instead of typing it all into the Criteria.
SQL:
Like "*ABC*" Or Like "DEF*" Or Like "*GHI"...
Is there a way to to do something akin to "Like KeywordTable?" This is in Access. Macros are acceptable.

Thanks.
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,393
Office Version
  1. 365
Platform
  1. Windows
What I would probably do is create it in VBA. You can use DAO/ADO recordsets, to loop through your "Keyword" table, and create your long string of "OR" statements.
Then, you can write the SQL code you need for your query and apply it.
Here is a link that shows you how run SQL code from VBA: Build SQL statements that include variables and controls

Here is also a little hint. To figure out what your SQL code needs to look like, using Access's query builder, create a simple query that has what you are looking for, but only with the first few "OR" statements. Then, switch the query to SQL View. This is what the SQL code you are trying to create needs to look like (just with more OR statements). Then, when you are using VBA to build this, you can use a MsgBox command to view your SQL Query string. You can then compare it to the sample you created, and keep working this way until you have it correct.

Here is a link that shows you how to loop through all the records in your Keyword table to create the criteria portion of your SQL string:
 

Watch MrExcel Video

Forum statistics

Threads
1,118,278
Messages
5,571,280
Members
412,374
Latest member
Nagelgal
Top