Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi folks, I am new to VB (from A

Status
Not open for further replies.

BrianB

Programmer
Oct 2, 2000
186
0
0
US
Hi folks,

I am new to VB (from Access VBA) and have what must be a simple problem.

I have a table of records containing both ID numbers and names. I want a combo box that displays the names yet stores the numbers. In Access, one would put a combo box on the form, set it to two columns with column 0 set to zero width. Then one would set the combo’s rowsource to a query with SQL of:

SELECT id, name FROM table ORDER BY name;

In VB, we have to use the AddItem method. How do I get a combo box that stores one value, but displays another? Indexes must be sequential, starting with zero, so they are not what I want.

This is so simple that there must be an easy answer to this. Thanks!

-Brian
 
if you take Microsoft Forms2 Object Library then you have a Combox with Collumns

Or

Do While Not Table.Eof

combobox.Additem Table!ID & space(5) & Table!Name

Table.MoveNext

Loop

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
Brian,

My proposal uses DBGrid and ADO controls instead of ComboBoxes.

Use the ADO control to fetch your records (both the number and name), tie this control to the Grid control. The grid control will be forced to display only the name. When the user picks the name that he wants, the DBGrid will bookmark it for you. Then based on this bookmark you can retrieve the number.

Not sure if this is feasible for you, but just wanted to suggest ...

- Subha :) Nothing is impossible, even the word impossible says I'm possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top