filtering with listboxes?

J

justin_vasko

is it possible to apply a filter to a listbox, based on a value received from
a combobox? any tips are greatly appreciated
 
N

Nikos Yannacopoulos

justin_vasko said:
is it possible to apply a filter to a listbox, based on a value received from
a combobox? any tips are greatly appreciated

Either use a saved query as the listbox's rowsource, and have the query
look up the combo for its criterion, like:
Forms![TheFormName]![TheComboName]
and requery the listbox every time the combo changes, or use some simple
code in the combo's Change event like:

strRS = "SELECT FiedX FROM MyTable WHERE FieldY = " & Me.ComboName
Me.ListboxName.Recordsource = strRS

In the above sample code I have assumed the combo / FieldY to be
numeric; if text, then:

strRS = "SELECT FiedX FROM MyTable WHERE FieldY = '" & Me.ComboName & "'"

HTH,
Nikos
 
Top