Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ComboBox VB6 ItemData, List and other properties.

Posted on 2010-08-31
5
Medium Priority
?
735 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

650 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