Make your own free website on Tripod.com
Move Multiple Items From One List Box To Other List Box/Combo Box

This code will show you how to move multiple selected items from one list box to other List Box, or other Combo Box.

Preparations

Add 2 List Boxes and 1 Command Button to your form.
Set List1 MultiSelect property to 1 - Simple.

Form Code

Private Sub Command1_Click()
'if List1 is empty - exit, to avoid error
   
If List1.ListCount = 0 Then Exit Sub
    Dim CurItem As Integer
    CurItem = 0
    Do
'if the item is selected
      If List1.Selected(CurItem) Then
'add it to the second List Box. If you want to add it to Combo Box,
'change the "List2" below with your combo Box name
'for example: Combo1.AddItem List1.List(CurItem)

         List2.AddItem List1.List(CurItem)
'and delete it from List1 List Box
         List1.RemoveItem (CurItem)
      Else
        CurItem = CurItem + 1
      End If
    Loop Until CurItem = List1.ListCount
End Sub

Private Sub Form_Load()
'add few items to the List Box
    For i = 1 To 10
        List1.AddItem "Item " & i
    Next
End Sub

Go Back