• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

Additem (multiple) from selected in listbox into combobox


I have a listbox that when you select an item it adds it into a combo box.  This is all working fine but I wish to add the value from listbox column 1 into combo box column 1 and then the value from listbox column 2 into combobox column 2.  For some reason when I try to add the second parameter to specify the column I get an error.  Below is the current code that I am using

Private Sub lbxProduct_Change()

Dim iCount, i As Integer
Dim strProd, strProd2 As String

    iCount = 0


    For i = 0 To lbxProduct.ListCount - 1
        If lbxProduct.Selected(i) Then
            iCount = iCount + 1
            strProd = lbxProduct.List(i, 0)
            strProd2 = lbxProduct.List(i, 1)
            With cboPrimaryProduct
                .AddItem (strProd, 0)                                     'This is where the error is
                .AddItem (strProd2, 1)
            End With
        End If
    Next i
    lblTest.Caption = iCount

End Sub
1 Solution
Additem adds a row, so add the first column data, then add the second column data into the row.

            With cboPrimaryProduct
                .AddItem strProd
                .List(.ListCount - 1, 1) = strProd2
            End With
wobbledAuthor Commented:
Brilliant, Thanks for that
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now