filter in form

  • Thread starter Thread starter Ian
  • Start date Start date
I

Ian

I have a form with a list of client name's, addresses,
etc... To search by address I've greated a parameter
query that let's me do a wild card search (*&[enter
parameter}&*). Which works ok but I have to relaunch the
form every time I want to modify the search.

I've seen a custom program where at the top there are 3
text boxes for first name, last name and address. You
can enter all or part of any of the three fields and the
form automatically filters for those parameters.

My question is how do I create the text boxes to act as
filters for part of the field I'm searching for?

Thanks.
 
Ian,

I shall assume for this example that the the fields in the form's
recordsource are called FirstName, LastName and Address.

Add a header section to the form, and put your filter criteria text
boxes there; I'll assume the names txtFName, txtLName and txtAddress for
this example. Next, add a command button to apply the filter, and put
this code behind its Click event:

vFltr = "FirstName Like '*" & Me.txtFName & "*'"
vFltr = vFltr & " AND LastName Like '*" & Me.txtLName & "*'"
vFltr = vFltr & " AND Address Like '*" & Me.txtAddress & "*'"
Me.Filter = vFltr
Me.FilterOn = True

In theory, you could check for nulls (no entry) and skip the pertinent
parts of the where clause in the interest of performance, but the
difference would only be noticeable on very big tables.

HTH,
Nikos
 

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

Back
Top