Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How can I pass multiple values with a combo box

Posted on 2006-03-31
Medium Priority
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
  • 2
  • 2
LVL 77

Assisted Solution

GrahamSkan earned 100 total points
ID: 16346618
There is an ItemData (long integer) property for each item in the list.
LVL 14

Accepted Solution

Shiju Sasidharan earned 100 total points
ID: 16347874
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
ID: 16347880
to retrieve it back use


Author Comment

ID: 16361919
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

ID: 16362949
I just figured it out.

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


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

564 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