Using Combo box to pull data using "Like"

AgDawg

Registered User.
Local time
Today, 07:03
Joined
Oct 12, 2012
Messages
24
I am not sure I am doing this correctly but I have a combo box called cboactives with specific names to choose from. What I want the form to do is filter on a column where I have combined 3 columns of actives together. So the form will filter if one of those values is any of those three columns. So I have a macro setup right now trying to filter for anything "Like" what has been selected in the combo box. I am thinking there might be a better way through vba. Here is what I have in the where condition of the filter macro:

Code:
((([Active1] & " " & [Active2] & " " & [Active3]) Like "*" & "[me.cboactives]" & "*"))="'" & [Screen].[ActiveControl] & "'"
Any help is appreciated.

This is in Access 2013

-Brad
 
Last edited:
Code:
& "[me.cboactives]" &


Suppose me.cboactives contains "plog rules". With the above code, you are literally putting these characters into your query:

[me.cboactives]

When you put quote marks around something, you are putting whatever is inside those quote marks into the string. You want to use [me.cboactives] as a variable and use the value it contains. To do that, you don't put quote marks around it.

I also think that means you want quote marks around all those [Active] variables in the first part.
 
So the form will filter if one of those values is any of those three columns.

Code:
((([Active1] & " " & [Active2] & " " & [Active3]) Like "*" & "[me.cboactives]" & "*"))="'" & [Screen].[ActiveControl] & "'"
If one or more of those fields is indexed, you've basically lost the benefit of indexing by combining the fields and by using the LIKE operator with the wildchard.

Perform the search on each field by using the OR predicate:
Code:
[Active1] = [Forms]![FormName]![FieldName] OR
[Active2] = [Forms]![FormName]![FieldName] OR
[Active3] = [Forms]![FormName]![FieldName]

NB: I suspect that your table isn't properly normalised. The indicator are the ActiveN fields.
 

Users who are viewing this thread

Back
Top Bottom