[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Additem (multiple) from selected in listbox into combobox

Posted on 2006-05-24
Medium Priority
Last Modified: 2008-03-03

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
Question by:wobbled
LVL 76

Accepted Solution

GrahamSkan earned 2000 total points
ID: 16751756
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
LVL 17

Author Comment

ID: 16759514
Brilliant, Thanks for that

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question