Is using IN enough?
i.e.
select * from my_table where column_name in ("ABC", "MOP");
You can also replace the IN clause with a choice from another table.
You can also use the VBA function:
select * from my_table where IsValidColumnName(column_name);
IsValidColumnName will be a simple function that returns bool if it matches any conditions you want.
To add a function, create a new module, and then you can enter something like:
Public Function IsValidColumnName(columnName As String) As Boolean If columnName Like "ABC*" Or columnName Like "MOP*" Then IsValidColumnName = True Else IsValidColumnName = False End If End Function
Note that Like variables modified by LIKE in VBA use DOS wildcards, you had SQL Server questions in your question.
source share