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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box Selected Items

Status
Not open for further replies.

firsttube

Technical User
Apr 21, 2004
165
CA
I have a multi-select list box on a form with a button. When the user clicks the button, a VB onclick event runs that is supposed to open internet explorer and pass the selected values to an asp page. All that works fine except the passing of the selected values. How can I access the selected values of a list box in VB?

Code:
    Dim theList As String
    Dim i As Integer
    theList = ""
    

    For i = 0 To Me.theLstBox.ListCount - 1
        If Me.theLstBox.Selected(i) Then
            theList = theList & "," & Me.theLstBox.List(i)
        End If
    Next

the above code does not work. As you can see, I'm trying to populate the variable "theList" with the selected values separated by commas.

Any suggestions?
thanks


Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
I see nothing wrong with the code snippet. Have you tried stepping through the code to see what the flow is and how theList's value changes?

At the risk of asking the obvious, are any entries in the ListBox selected before the CommandButton is clicked?


Regards,
Mike
 
here is the code I got to work:
Code:
Dim i As Variant

 For Each i In Me.theLstBox.ItemsSelected
            theList = theList & Me.theLstBox.ItemData(i) & ","
        Next i



Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
Why didn't you say us you played with an Access.ListBox instead of a MSForms.ListBox ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top