1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Access VBA Filter for Multiple OR's

Discussion in 'Business Applications' started by Davecogz, Oct 24, 2009.

Thread Status:
Not open for further replies.
Advertisement
  1. Davecogz

    Davecogz Thread Starter

    Joined:
    Jan 26, 2009
    Messages:
    19
    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
     
  2. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    18,834
    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:

  3. Davecogz

    Davecogz Thread Starter

    Joined:
    Jan 26, 2009
    Messages:
    19
    Thanks so much OBP! I'd been boggling over it for a while. It's easy when you know how I guess.

    Best,

    David
     
  4. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    18,834
As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/871245