How do you choose multiple selections in a list box to be displaye

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone have the VB code that will allow you to display multiple
selection chosen in a list box.
 
Display them where?

The following would list them, separated by commas in a text box on the form:

Dim varItem As Variant
Dim strItemList As String
Dim ctrl As Control

Set ctrl = Me.lstYourListBox

' iterate through list box's ItemsSelected collection
' and build list if any items selected
If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected
strItemList = strItemList & ", " & ctrl.ItemData(varItem)
Next varItem

' remove redundant leading comma and space
strItemList = Mid(strItemList, 3)

' fill text box with list
Me.txtYourTextBox = strItemList
Else
MsgBox "No items selected.", vbInformation, "Warning"
End If

Ken Sheridan
Stafford, England
 

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

Back
Top