How can I pass multiple values with a combo box

Posted on 2006-03-31
Last Modified: 2010-05-01
I have a combo box setup on a vb form. I need to populate another combo box based on the value selected in the first one.
How can i pass the id of a record along with the name with a combo box?

This is part of my code that populates the combo box,

    Dim cb As ComboBox
    Set cb = Me.Controls(strComboName)
    While Not recResult.EOF
        cb.AddItem recResult.Fields(0)  

In my program i can retrieve the value the user sees but i want to pass an id field along with every name displayed so i can use it to run another query.

Can somebody help with this?
Question by:dayiku
    LVL 76

    Assisted Solution

    There is an ItemData (long integer) property for each item in the list.
    LVL 14

    Accepted Solution

    GrahamSkan is right

    While Not recResult.EOF
            cb.AddItem recResult.Fields(0)  
            cb.ItemData(cb.NewIndex)= recResult.Fields(1)   ' Where  recResult.Fields(1) must be a integer or long data
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    to retrieve it back use


    Author Comment

    Thanks for the information.
    I tried to retrieve the value but it only gives me the last entry. I want the current selected value.
    How do i do that?

    eg    id =21343  Name=Dept1
            id =21445 Name=Dept2

    When the user selects Dept1 i want the id.

    Author Comment

    I just figured it out.

     TO retrieve value it should be cb.ItemData(ListIndex)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now