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. Advertisements

  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. Advertisements

  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. Advertisements

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. DeVille

    Wildcard Filter Code

    DeVille, Sep 12, 2003, in forum: Access Forms
    Replies:
    2
    Views:
    151
    DeVille
    Sep 12, 2003
  2. jimtyson

    Filter on Form and Apply Filter

    jimtyson, Nov 7, 2003, in forum: Access Forms
    Replies:
    0
    Views:
    146
    jimtyson
    Nov 7, 2003
  3. Chris
    Replies:
    1
    Views:
    175
    Rick Brandt
    Jan 9, 2004
  4. Chickadees98
    Replies:
    2
    Views:
    97
    John Vinson
    Nov 15, 2005
  5. jgeniti
    Replies:
    4
    Views:
    293
    jgeniti
    Jan 29, 2007
  6. Jahlu

    Wildcard Filter Issues

    Jahlu, Aug 10, 2007, in forum: Access Forms
    Replies:
    6
    Views:
    159
    Douglas J. Steele
    Aug 14, 2007
  7. PHisaw

    Open Report From Form With Wildcard

    PHisaw, Dec 18, 2007, in forum: Access Forms
    Replies:
    3
    Views:
    100
    DoveArrow
    Dec 19, 2007
  8. larochy

    Me.Filter using wildcard in formula

    larochy, Feb 25, 2009, in forum: Access Forms
    Replies:
    2
    Views:
    161
    larochy
    Feb 25, 2009
Loading...