filter combo box

A

angie

i have a form with 4 combos and a listbox. how can i limit(filter) the values
of a combo based on the values selected on another combo and the list box?
 
S

Scott Lichtenberg

Angie,

You need to change the rowsource property of the dependent combos boxes
based on the value selected in your primary combo box. Add code like the
following to the AfterUpdate event of your combo box or list box.

Dim strSQL as string

strSQL = "SELECT Field1, Field2, etc FROM MyTable WHERE Field1 = " &
Me!cboCombo1
Me!cboCombo2.RowSource = strSQL
 
S

Shimon

What would the code be to filter the records of the form, based on all
the combo boxes, where when the form opens there are no values in the
combo boxes, and as I choose values from the combo boxes i want the
records filtered as I go.
Shimon
 
S

Scott Lichtenberg

Shimon,

To filter records in the form's recordsource, you will want to use the
form's Filter and FilterOn properties. You would put the code to apply the
filters in the AfterUpdate event of your combo boxes. Here's a sample:

Dim strSQL as String

strSQL = "SELECT Field1, Field2, etc. FROM MyTable WHERE Field1 = " &
Me!cboCombo1 & " AND Field2 = " & cboCombo2

Me.Filter = strSQL
Me.FilterOn = True

Look up these properties in the online help. One note - you might also want
to but a command button on your form to turn off filtering to allow your
users to see all records.
 

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

Top