Listboxes will show multiple items in the list and display as many as it can
within the size of the listbox. Combo boxes have a single textbox with a
drop down arrow to open a list of items. However, both work similarly.
The Control Source is used to bind the control to a field in the form's
recordset or to create a calculated control. The Row Source is used to fill
the list with selectable items.
The box is capable of more than one column. In a combo box, the first
visible column is what will display in the textbox portion, although all
visible columns will be seen in the drop down list. This is frequently used
when you have a "lookup table" that contains a list of items, such as a name
prefix list (Mr, Mrs, Dr, etc). If this table has an ID field as well as the
text field, you may want both fields in the combo box. The ID field would be
meaningless to the user, so you would set the width of this field to zero
(hide it) and set this field as the Bound Column. In the table that you were
storing a person's name, you would then store the value of this ID field,
not the text. Later, such as in a report, when you wanted to have the name
say "Dr. John Doe", you would use a query to supply data to the report. You
would add both of these tables to the query and link them on the ID field
(the common field between them). This will allow you to get the text value
from the lookup table.
Another use (the one you appear to be wanting) for the combo box is to use
it as an unbound control to select items as filters for a query. For this,
you would use a query for the Row Source of the combo box. The query would
select values from the recordset (table) that you are wanting to filter. You
would then refer to this combo box in the query (another query, not the one
used as the Row Source) that is being used to filter the recordset.
Example:
I have a table named Table1 with the fields Address, City, State, and Zip. I
want a combo box to select which states I want to see. The combo box is
called cboState and is on a form called frmForm1. The query for the Row
Source of the combo box would be:
SELECT DISTINCT State FROM Table1 ORDER BY State;
The distinct keyword would give me each state only once in the drop down
list. I would then use a query to filter the table's results by the state
selected in the combo box.
SELECT Table1.Address, Table1.City, Table1.State, Table1.Zip
FROM Table1
WHERE Table1.State Like "*" & Forms!frmForm1!cboState & "*";
The Like operator will return items using "pattern matching". The asterisks
are "wild cards". If I asked for items "Like *ee*" it would find beep, been,
or any other word with "ee" in it. The advantage of doing this instead of
WHERE Table1.State = Forms!frmForm1!cboState
Is that if you don't make a selection in the combo box (i.e. the box is
Null) then you get all records returned.
Like "*" & Null & "*" will evaluate to Like "**"
As you can see, this is wild cards only (there is nothing to limit the
selection), so you get everything.
You would repeat the above for each of the combo boxes you want on your
form. In the final query (the one you're trying to filter using the combo
boxes), you would have only the one query, with criteria as mentioned above
for each of the combo boxes listed under their associated fields in the
query design window.
The view above is the SQL view of the query. In the query design view
window, you would place
Like "*" & Forms!frmForm1!cboState & "*"
in the Criteria box under the State field. Access would then generate the
SQL as displayed above. It will probably add a few parentheses to the SQL,
it tends to generate more of these than it needs, but that's usually not a
problem.