Filtering one listbox from another listbox

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
 
A

Arvin Meyer [MVP]

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
 

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