# Solved: Access VBA Filter for Multiple OR's



## Davecogz (Jan 26, 2009)

Hello all,

This should be a simple enough question for anyone who knows more than I do about VBA (and there are a fair few of you that do!)

I am setting up a filter on a form for a particular query. The way this particular database was designed the data needs to be filtered at this stage and not at query-level.

It seems easy enough to apply a filter for a given string:

Me.Filter = "WordType = ""Verb" & """"

But how would I apply one if there were many OR criteria. Explanation of all those <"> s and <'> s would be much appreciated too. I want it to say something like:

Me.Filter = "WordType = ""Verb" & "OR Noun" & """"

I don't know where the OR part goes.

Thanks in advance,

Dave


----------



## OBP (Mar 8, 2005)

Dave, the """ and "'" are used to get the correct Field/variable Type when matching data,
i.e. to match a number to a Text or Text to a number. 
Your attempt to do what you want is quite close to what is I think is going to be required.
See the attached database for an example.
It does not have any checks built in to ensure that there is something in either of the 2 filter fields.
This is the code for those who can't be bothered with the database

Dim strFilter As String
strFilter = "data = '" & Me.filter1 & "'"
strFilter = strFilter & "Or data = '" & Me.filter2 & "'"
Me.Filter = strFilter
Me.FilterOn = True


----------



## Davecogz (Jan 26, 2009)

Thanks so much OBP! I'd been boggling over it for a while. It's easy when you know how I guess.

Best,

David


----------



## OBP (Mar 8, 2005)

Dave, we all have to learn it one way or another and it is very powerful.
it also works for Queries using the QueryDef, see this thread.
http://forums.techguy.org/business-applications/868168-what-method-take-criteria-search.html

Can you mark the thread as Solved please?


----------

