Wildcard to filter form

Discussion in 'Access Forms' started by DeVille, Feb 18, 2004.

  1. DeVille

    DeVille Guest

    Hi I have this piece of code which uses an 'on-click'
    event procedure on my form to filters my records. The
    field is named 'Subject' and the code brings up a
    dialogue box which I then type the first part of a
    sentence and it finds all records which start with that
    text. Eg if I type 'TH' it would bring back all records
    that start with words like 'THE', 'THERE' or 'THAT' etc.
    I would like to change the code so that it finds records
    where the wild card is in the middle of the text. Eg if I
    typed "OO' it would find 'BOOK' or 'SCHOOL' etc.
    If any one can help me thanks in advance. see code
    below

    Let CurRecNo = Form.CurrentRecord
    QryFld = " Subject "

    Me.Filter = "[Subject] Like '" & InputBox("Enter
    Subject") & "*'"
    Me.FilterOn = True
     
    DeVille, Feb 18, 2004
    #1
    1. Advertising

  2. DeVille

    Dan Artuso Guest

    Hi,
    Try this:

    Me.Filter = "[Subject] Like '*" & InputBox("Enter Subject") & "*'"
    --
    HTH
    Dan Artuso, Access MVP


    "DeVille" <> wrote in message news:12e5301c3f66c$72d2e2f0$...
    > Hi I have this piece of code which uses an 'on-click'
    > event procedure on my form to filters my records. The
    > field is named 'Subject' and the code brings up a
    > dialogue box which I then type the first part of a
    > sentence and it finds all records which start with that
    > text. Eg if I type 'TH' it would bring back all records
    > that start with words like 'THE', 'THERE' or 'THAT' etc.
    > I would like to change the code so that it finds records
    > where the wild card is in the middle of the text. Eg if I
    > typed "OO' it would find 'BOOK' or 'SCHOOL' etc.
    > If any one can help me thanks in advance. see code
    > below
    >
    > Let CurRecNo = Form.CurrentRecord
    > QryFld = " Subject "
    >
    > Me.Filter = "[Subject] Like '" & InputBox("Enter
    > Subject") & "*'"
    > Me.FilterOn = True
    >
     
    Dan Artuso, Feb 18, 2004
    #2
    1. Advertising

  3. DeVille

    John Vinson Guest

    On Wed, 18 Feb 2004 14:13:33 -0800, "DeVille"
    <> wrote:

    >I would like to change the code so that it finds records
    >where the wild card is in the middle of the text. Eg if I
    >typed "OO' it would find 'BOOK' or 'SCHOOL' etc.
    >If any one can help me thanks in advance. see code
    >below
    >
    >Let CurRecNo = Form.CurrentRecord
    >QryFld = " Subject "
    >
    >Me.Filter = "[Subject] Like '" & InputBox("Enter
    >Subject") & "*'"


    A LIKE clause uses wildcards: * means "match any string of zero or
    more characters", ? means "match any single character", # means "match
    any digit", etc. So if you want any string of characters, followed by
    a selected string, followed by any other characters you just need a *
    before and after the subject:

    "[Subject] Like '*" & InputBox("Enter Subject") & "*'"

    If the user types in OO this will be expanded to

    [Subject] LIKE '*OO*'

    and will match as you requested.

    John W. Vinson[MVP]
    Come for live chats every Tuesday and Thursday
    http://go.compuserve.com/msdevapps?loc=us&access=public
     
    John Vinson, Feb 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DeVille

    Wildcard Filter Code

    DeVille, Sep 12, 2003, in forum: Access Forms
    Replies:
    2
    Views:
    56
    DeVille
    Sep 12, 2003
  2. Jahlu

    Wildcard Filter Issues

    Jahlu, Aug 10, 2007, in forum: Access Forms
    Replies:
    6
    Views:
    44
    Douglas J. Steele
    Aug 14, 2007
  3. larochy

    Me.Filter using wildcard in formula

    larochy, Feb 25, 2009, in forum: Access Forms
    Replies:
    2
    Views:
    58
    larochy
    Feb 25, 2009
  4. JB

    filter with wildcard

    JB, Jun 26, 2006, in forum: Access Forms Coding
    Replies:
    11
    Views:
    104
  5. AccessIM

    Filter also is a wildcard

    AccessIM, Apr 24, 2009, in forum: Access Queries
    Replies:
    4
    Views:
    52
    AccessIM
    Apr 24, 2009
Loading...

Share This Page