Results 1 to 4 of 4
  1. #1
    kjuelfs is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    6

    "OR" Filter

    Hello,

    I'm trying to build a string for the Filter property to be set in the VBasic Code.

    The syntax which works when doing a manual "advanced" filter directly in the form is as follows: Like "NUMBER1*" Or Like "NUMBER2*"

    I need all entries with the one number or the other. In the code I want to do the same for 1 to n different numbers.



    What does the syntax look like? I've tried these:

    Me.Filter = ([FIELD] Like "NUMBER1*") OR ([FIELD] Like "NUMBER2*")
    Me.Filter = ([FIELD] Like "NUMBER1*" OR [FIELD] Like "NUMBER2*")
    Me.Filter = ([FIELD] Like "NUMBER1*" OR Like "NUMBER2*")
    Me.Filter = [FIELD] Like "NUMBER1*" OR Like "NUMBER2*"

    I also want to add the condition... AND [OTHER_FIELD] = "TYPE"... what would this look like in combination with the OR filter string?

    Thanks in advance

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Is the field you designate as [FIELD] a number or text datatype? I assume it is text since you are using the LIKE operator.

    I would think something like this would work (air code, not tested):

    dim myFilter as string

    for i=1 to n
    myFilter = myFilter & "([FIELD] Like 'NUMBER" & i & "'*) OR "
    next i

    'now strip off the last OR and the following space (ie 3 characters)

    myFilter= left(myFilter, len(myFilter)-3)

    myFilter=myFilter & " AND [OTHER_FIELD] = 'TYPE'"
    me.filter=myFilter

  3. #3
    kjuelfs is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    6
    Thanks, that worked. I was just missing the ' marks.

  4. #4
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Glad to here you came to a solution. Best of luck on your project.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2010, 10:22 AM
  2. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM
  3. Create "reset filter" button
    By vanlanjl in forum Access
    Replies: 0
    Last Post: 03-03-2009, 07:36 AM
  4. Replies: 2
    Last Post: 08-31-2006, 12:19 PM
  5. "Count" and "Countif" in Reports
    By JMantei in forum Reports
    Replies: 1
    Last Post: 06-20-2006, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums