Solved

ComboBox VB6 ItemData, List and other properties.

Posted on 2010-08-31
5
707 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

773 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