VB6 Combo Box - Need to display Emp name but send Empid to the database

Hi Experts,
I am using Combo box in VB6. I am loading this combo box with employee names from database (in form_load event). I see two properties for combo box, one being datafield and the other being 'list' but I dont know how I can use them.
Could I use one of these columns, which does not display, to hold empid and once the user selects an Employee name, then I send the corresponding empid from that field to the database? Please suggest with code examples.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Omar McKoyHead of Infrastructure OperationsCommented:
This is possible through using the ItemData property.

' Cycle through the result set and populate combobox
Do While Rs.EOF = False
                ' Add new item to "Employee" Combobox
                cmbEmpployee.AddItem Rs![<Emplyee Name>]
                cmbEmpployee.ItemData(cmbCloseFor.NewIndex) = Rs![<Employee ID>]

' To retrieve the employee id
Mortaza DoulatyCommented:
something like this:

    Dim i As Integer

    While Not rst.EOF
        Combo1.AddItem rst!Name
        Combo1.ItemData(i) = rst!EmployeeID
        i = i + 1

But something may not be a good news! and that is: the ItemData only accepts numeric data.
In order to do what you said, you can use an array which holds the EmloyeeID, the index of the comobe and that array, should be the same. (but not neccesary)
The code might look like:

    Dim i As Integer
    Dim Arr() As String
    While Not rst.EOF
        Combo1.AddItem rst!Name

        ReDim Preserve Arr(i) As String
        Arr(i) = rst!EmployeeID
        i = i + 1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.