Wildcard to filter form

D

DeVille

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
 
D

Dan Artuso

Hi,
Try this:

Me.Filter = "[Subject] Like '*" & InputBox("Enter Subject") & "*'"
 
J

John Vinson

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.
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top