Transfer multi selection from list box to text box

Hello all

I have a list box (check style) in form45.

What i want to do it to be able to select, 1 or more selection from the list and when i click on the button, it will transfer all items selected from the list in my Form44.carrier_names (Textbox).

For ex: if i have only once selected in my list box, called "26". Then it will put "26" in my Form44.carrier_names (Textbox).

But is i have for example 3 selection, "08" "21" and "28". then it will transfert to the text box like this:
08
21
28



How can i do this please.

Thanks again for your help.


Form44.carrier_names = form45. List1

Open in new window


save-from-list.JPG
LVL 11
Wilder1626Asked:
Who is Participating?
 
Martin LissConnect With a Mentor Older than dirtCommented:
Like so


Dim lngIndex As Long

For lngIndex = 0 To List1.ListCount - 1
    If List1.Selected(lngIndex) Then
        Text1.Text = Text1.Text & List1.List(lngIndex) & vbCrLf
    End If
Next

Open in new window

0
 
Martin LissOlder than dirtCommented:
Set the Multiline property of the textbox to True. Then loop through the Listitems looking for those selected and then add them with vbCrLf at the end of each one.
0
 
Wilder1626Author Commented:
Thanks, this is perfect
0
 
Martin LissOlder than dirtCommented:
Thanks. If you want to get rid of the last vbCrLf do

Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 2)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.