Link to home
Start Free TrialLog in
Avatar of dayiku
dayiku

asked on

How can I pass multiple values with a combo box

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)  
    recResult.MoveNext
    Wend

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?
SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
to retrieve it back use

        cb.ItemData(Index)
Avatar of dayiku
dayiku

ASKER

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.
Avatar of dayiku

ASKER

I just figured it out.

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


Thanks.