List box Question

G

Gsurfdude

Hello,

I have form with a list box who's record source is a table. It is set to
multi select. When selecting multiple rows how can I hide the rows that are
selected (highlighted) without regenerating the record source?
 
K

Klatuu

This is going to be a bit tricky. You will have to use a query based on the
table instead of the table directly.
Now, you need a hidden text box control on your form you will use to filter
the list box.
Add a Where Clause to the list box row source query like this:
WHERE SomeField Not In(Me.txtListBoxFilter)

If the hidden control Me.txtListBoxFilter is Null, all records will show in
the list box.

When you want to hide the selected items, you will have to populate the text
box with a list of the selected items separated with commas. Here is how you
can do that.

Dim varItem As Variant

If Me.MyListBox.ItemsSelected.Count = 0 Then
Me.MyListBox = Null
Else
With Me.MyListBox
For Each varItem In .ItemsSelected
Me.txtListBoxFilter = Me.txtListBoxFilter & _
"""" & .ItemData(varItem) & """, "
Next varItem
End With
Me.txtListBoxFilter = Left(Me.txtListBoxFilter, _
Len(Me.txtListBoxFilter) - 2))
End If
Me.MyListBox.Requery
 

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