Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi select List Box

Status
Not open for further replies.

rfoye

Programmer
Oct 15, 2004
40
US
I've seen plenty of questions and answers about how to save down the selections from a multi-select listbox, but I now need to go the other way: I need to select items in the list box based on the values in an array.

I assume I need to loop through the rows of the list box, but is there a .SetSelection or similar method?

Is this possible, or am I whistling in the dark?

-------------------
Rob Foye
Database Management
Regions Bank
 
Perhaps:
Code:
Private Sub Form_Current()
'Array for testing
astrSel = Split("a,c,d,e", ",")
'Join array
strSel = Join(astrSel, ",")
'Select items
For i = 0 To Me.lstList.ListCount
    If InStr(strSel, Me.lstList.Column(0, i)) > 0 Then
        Me.lstList.Selected(i) = True
    End If
Next
End Sub
 
Thanks, Remou.

Not only did you answer my question (the For...Next loop does exactly what I need), you showed me how to streamline my code. I had been parsing a delimited text field into an array, when all I really needed was to use the InStr function on that text field!

-------------------
Rob Foye
Database Management
Regions Bank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top