Search string through form

R

Ramesh

Hi,

Is there a way i can search for a string in a field, like a filter? Right
now, i am right clicking and using Filter for *<name>* to find records with
<name> in the field.

Tried to use a parameter query to input the string, but that doesnt work.
Ideally i d liek to be prompted for the string and then all the records
which contain the string be displayed.

Thanks for any inputs.
ramesh
 
R

Rick Brandt

Ramesh said:
Hi,

Is there a way i can search for a string in a field, like a filter? Right now,
i am right clicking and using Filter for *<name>* to find
records with <name> in the field.

Tried to use a parameter query to input the string, but that doesnt
work. Ideally i d liek to be prompted for the string and then all the
records which contain the string be displayed.

Thanks for any inputs.
ramesh

In Clcick event of a button...

Dim RetVal as string
RetVal = InputBox("Please Enter Text to Filter On")

If RetVal <> "" Then
Me.Filter = "SomeField = '" & RetVal & "'"
Me.FilterOn = True
End If
 
D

Dave Emmert

Ramesh,

Rick is correct, though I would prefer to change his line:

Me.Filter = "SomeField = '" & RetVal & "'"

to:
RetVal = Replace(RetVal, "'", "''")
Me.Filter = "SomeField Like '*" & RetVal & "*'"

This will allow you to use wildcards and apostrophes with the filter.

Dave Emmert
 
Top