Making a search box

J

Janet Millter

I want to make a box on my form that I can type stuff in to search for
record. Like last name, for example.

I'm finding information about how to do this at various places, but i
all seems to assume I have knowledge that I don't, and I'm gettin
really confused. I haven't been able to find a resource that doesn'
seem to start in the middle.

Any suggestions
 
G

Graham Mandeno

Hi Janet

It would have helped if you'd posted some code to show how close to the
"middle" you have got already :)

There are a number of ways to do this... one is to set a filter on your
form. here is a simple example:

Let's say your last name field is called "LastName". Add a textbox to your
form named "txtFilterLastName". Leave it unbound (ControlSource is blank)
and in the properties sheet, scroll down to AfterUpdate. Type a left square
bracket [ in the property box ("[Event Procedure]" will appear) and then
click the build button on the right [...].

The VBE code window should open with something looking like this:

Private Sub txtFilterLastName_AfterUpdate()
| <<< cursor
End Sub

At the cursor, type (or paste) these lines of code:

If IsNull(txtFilterLastName) Then
Me.FilterOn = False
Else
Me.Filter = "[LastName] like """ & txtFilterLastName & "*"""
Me.FilterOn = True
End If

Now, if you open the form and type some letters (e.g. "mil") in the textbox,
and press Enter, your form should be filtered so as to show only those
people with names such as Millter, Miller, Milson, etc.
 
Top