Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple way of Using Combo Boxes to search for records on a Form

Status
Not open for further replies.

gobble

Technical User
Mar 21, 2002
28
GB
Hi there
I was wondering if there was a simple way in which to have a search button on a form with thousands of records. This button is to open a small form with two combo boxes, one represents the categories and depending on what you choose the second combo box will show values which are shown on the previous form. When a value is selected I would like to have a button when clicked searches the previous form for the records matching this value and display them. Then an Show All button will bring back all records again. Is there a simple way of doing this?

Any help would be great!

Thanks in advance
 
To say is there a simple way the answer depends on your ability. If I understand what you're asking which I normally don't I believe you want to create an unbound form which will look at your current records and show Categories and based on your selection there display something else?

If that is correct here is what I would do.
1. Create a new unbound form and create an unbound *I prefer a list box*

2. On the Load event of the form I would run some SQL to populate the list box.
Me.List1.Rowsource = _
"SELECT DISTINCT Category FROM MyTable " & _
"WHERE Category IS NOT NULL"

3.Now Create a second Unbound List box or combo whatever and in the afterupdate event of the first one I would add the following code.
With Me.Listbox2
.Rowsource = _
"SELECT DISTINCT Whatyouwant FROM MyTable " & _
"WHERE Category = " & chr(34) & Me.List1 & chr(34)
.Requery
End With

4. Now you can tie it into a button or double click event of the second list box like this.
Docmd.OpenForm FormName:="PlaceNameHere" , _
WhereCondition:="MyformID = " & Me.List2

not knowing your data type the last line can also be
WhereCondition:="MyFormID = " & Chr(34) & Me.List2 & Chr(34)

Now to turn the filter off just add filteron=False in the proper event. Life's a journey enjoy the ride...

jazzz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top