Filtering one listbox from another listbox

  • Thread starter Thread starter ghull
  • Start date Start date
G

ghull

I have two list boxes
List box one is called lstElevation
List box two is called lstCabType
Both boxes are set at extended select
I need to filter the second list box from the multi selected items from the
first list box
What is the best approach for doing this?
Thanks for your help
 
The example you gave me will not work on a multi select list box

Is their a way to make a multi select box filter a second list box?

Yes, but it isn't simple. First make a hidden textbox to hold the results of
each click of the multi-select. Then use a piece of code like:

With Me!lstElevation
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ","
Next varItem
If strList <> "" Then
strList = Left$(strList, Len(strList) - 1)
End If
Me.txtSelected = strList
End If

End With

Where lstElevation is the listbox and txtSelected is the hidden, unbound
textbox. Don't forget to Dim your other variables.

Now use the textbox in code as the rowsource property of the second listbox:

Dim strSQL
strSQL = "SELECT * FROM YourTable WHERE ID) In (" & Me.txtSelected & ");"
Me.lstWhatever.Rowsource = strSQL
 
Back
Top