How do I make a search form with a textbox and a combobox?

  • Thread starter Thread starter bern
  • Start date Start date
B

bern

Hi,

I want to create a search form which works by letting the
user select from a combobox which field to search in, and
a textbox in which the user may enter his search string.
Does anyone know how I can do this?
For instance, the user selects "Last Name" from the
combobox and enters "Clinton" in the textbox. When the
command button is clicked, the first post is shown, and a
second command button (labeled "show next") will display
the next post which matches the criteria (if there are
any).
Thanks a lot for any help.

Cheers
 
Hi Bern,

This should get you started. First, place a combobox, an unbound textbox,
and a command button on the form. Then set the Row Source of the combobox
to the table/query which contains the fields you want to search, and set the
Row Source Type to FieldList.

Next, in the click event of the command button, write the following lines of
code (replace cboField and txtString to the actual names of your combobox
and textbox controls):

Me.Filter = "[" & cboField.Value & "] Like '*" & txtString.Value & "*'"
Me.FilterOn = True

This will search anywhere in the selected field for the string provided in
the text box. If you want to remove the filter, use another command button
and set the FilterOn property to False.

Note that the example will only work on text fields, and you will have to
modify it for use with numeric or other types of data.

Hope this helps,
- Glen
 
Back
Top