Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Solved: Access VBA Filter for Multiple OR's


(!)

Davecogz's Avatar
Davecogz Davecogz is offline
Member with 19 posts.
THREAD STARTER
 
Join Date: Jan 2009
Experience: Intermediate
24-Oct-2009, 10:03 AM #1
Solved: Access VBA Filter for Multiple OR's
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's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,440 posts.
 
Join Date: Mar 2005
Location: UK
24-Oct-2009, 11:00 AM #2
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
Attached Files
File Type: zip ORFilter v 0.0.zip (11.2 KB, 250 views)
__________________
OBP
I do not give up easily

Last edited by OBP; 24-Oct-2009 at 11:06 AM..
Davecogz's Avatar
Davecogz Davecogz is offline
Member with 19 posts.
THREAD STARTER
 
Join Date: Jan 2009
Experience: Intermediate
24-Oct-2009, 01:14 PM #3
Success
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's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,440 posts.
 
Join Date: Mar 2005
Location: UK
24-Oct-2009, 01:20 PM #4
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-a...ia-search.html

Can you mark the thread as Solved please?
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑