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!

Loading combo with index field?

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
I am trying to load into a combo box Hospital Name and its ID as index. And then later get it out. But it doesnt work for some reason. This code works fine for a list but not for a combo box. What am i doing wrong?

Do While Not DBRec.EOF
cmbHospital.AddItem DBRec!Hospital_name
cmbHospital.ItemData(cmbHospital.NewIndex) = DBRec!HospitalID
DBRec.MoveNext
Loop


MsgBox (cmbHospital.ItemData(cmbHospital.ListIndex))
 
Do While Not DBRec.EOF
cmbHospital.AddItem DBRec!HospitalID & space(5) &
DBRec!Hospital_name
DBRec.MoveNext
Loop

cmbHospital.ListIndex = 0 Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Savok,
That should work. This is the method i use in my applications anytime i want a user to choose a parameter by name but i want to know what record number is associated with that name.

Code:
        Do While Not rs.EOF
            cbo.AddItem Trim(rs(Column))
            cbo.ItemData(cbo.NewIndex) = rs(columnrec)
            rs.MoveNext
        Loop

Heres a code snippet, it works every time. maybe you'll see a difference i'm not seeing.
You need to figure out why this isn't working. Inserting the id and name as one string will cause a lot of problems for you. This is what the .ItemData property is there for.
HTH Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top