Using VBA to select Items in multiselect Listbox

B

bymarce

How can you programatically select items in a multiselect list box based on
their lables? Certain groups of items in my multiselect listbox will be
frequently selected together. I want to have check boxes elsewhere on the
form that a user can click that will cause a group of items to be selected in
the list box. The list box itself is used to make an sql statement. Thanks.
Marcie
 
D

Dirk Goldgar

bymarce said:
How can you programatically select items in a multiselect list box based
on
their lables? Certain groups of items in my multiselect listbox will be
frequently selected together. I want to have check boxes elsewhere on the
form that a user can click that will cause a group of items to be selected
in
the list box. The list box itself is used to make an sql statement.
Thanks.
Marcie


Hi, Marcie -

I'm not sure what labels you're referring to, but you can select items in a
multiselect list box by setting the row's .Selected property. In deciding
whether or not to select a row, you can check the value of the bound column
for that row by referring to the .ItemData property; or, if you need to
look at some other column of the list box, you can use the .Column property.
For example:

'------ start of example code ------

Dim lngX As Long

With Me.lstMyListbox
For lngX = Abs(.ColumnHeads) To (.ListCount - 1)
'---------> Use this line to test the row's bound-column value:
' If .ItemData(lngX) Like "ABC*" Then
'---------> Use this line to test a particular column:
If .Column(1, lngX) Like "ABC*" Then
.Selected(lngX) = True
End If
Next
End With

'------ end of example code ------
 

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