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

User form multi select

Status
Not open for further replies.

JanTore

Technical User
Jun 9, 2001
34
NO
I've got a userform in Word with a listbox and a textbox which I want to fill with the selected items from the listbox. With the code below I only get the last selected item from the listbox to apear in the textbox.
Any ideas to help me out are appreciated

Code:
Dim i As Integer

Private Sub UserForm_Initialize()

    For i = 0 To 9
        ListBox1.AddItem "Choice " & (ListBox1.ListCount + 1)
    Next i
    
End Sub

Private Sub CommandButton1_Click()

    For i = 0 To 9
       If ListBox1.Selected(i) = True Then
            TextBox1.Text = ListBox1.List(i)
       End If
    Next i

End Sub
 
TextBox1.Text = ListBox1.List(i)

replaces contents of textbox each time...textbox1.text = listbox.list(i). so of course is last one.

textbox.text = textbox.text & listbox.list(i) increments selected listings.

maybe rethink, if u change listbox selections, AFTER, textbox contents NOT change unless u clear first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top