Solved

ComboBox VB6 ItemData, List and other properties.

Posted on 2010-08-31
5
710 Views
Last Modified: 2012-05-10
I am populating the Combobox list like this:
With rsContacts
        While Not .EOF
             
                cboContrProgramType.AddItem .Fields("ProgramDesc")
                cboContrProgramType.ItemData(cboContrProgramType.ListCount - 1) = .Fields("ProgramCode")
             
            .MoveNext
        Wend
    End With

On the form I see the "ProgramDesc".  AFter I made a selection how should I pass the ("ProgramCode") back to the database.

This is a foreign key in the table.
0
Comment
Question by:Aquarus
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33568282
It is:

    cboContrProgramType.ItemData(cboContrProgramType.ListIndex)


0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 33568703
Do this on the Click event of your object.
0
 
LVL 10

Accepted Solution

by:
3_S earned 500 total points
ID: 33569137
Change code to

Using cboContrProgramType.ListCount - 1 is not wrong but NewIndex is preferred.
With rsContacts
        While Not .EOF
             
                cboContrProgramType.AddItem .Fields("ProgramDesc")
                cboContrProgramType.ItemData(cboContrProgramType.NewIndex) = .Fields("ProgramCode")
             
            .MoveNext
        Wend
    End With


retrieving ProgramCode
 cboContrProgramType.ItemData(cboContrProgramType.ListIndex)

Open in new window

0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33569687
Wow... what's the difference of the accepted solution from the code I posted?
0

Featured Post

Technology Partners: 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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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