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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box woes WAS:"Hi folks, I am"-Sorry for lack of subject

Status
Not open for further replies.

BrianB

Programmer
Oct 2, 2000
186
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
 
Set rs = conn.Execute("Select * From SomeTable")
Do Until rs.EOF
Combo1.AddItem rs("SomeField")
Combo1.ItemData(Combo1.NewIndex) = rs("TheIndex")
rs.MoveNext
Loop
=========
This will populate the combo box for you using the index in a sequential manner.

aspvbwannab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top