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

combo box quest ion 1

Status
Not open for further replies.

sweetleaf

Programmer
Jan 16, 2001
439
0
0
CA
Hi there,

I have a form with a combo box which lists contact names.
I want to make it so that when a user clicks SAVE on this form the Contact_ID instead of the Contact name gets saved.

How do I do this?

Here's the code I'm using to populate the combo box:

Dim rstInc As New ADODB.Recordset
Dim intIndex As Integer
intIndex = 0
Dim db As Connection

Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;dsn=dev;uid=scott;pwd=tiger;"

rstInc.Open "SELECT contact_id,contact_name FROM MDU_INCUMBENT ORDER BY COMPANY_NAME ASC", db, adOpenForwardOnly, adLockReadOnly

Do Until rstInc.EOF
frmAddProjectWizard.txtIncumbent.AddItem rstInc("contact_id") & rstInc("contact_name"), intIndex
intIndex = intIndex + 1
rstInc.MoveNext
Loop

db.Close
Set db = Nothing

Thanks so much!!

 
Hi,

Seems to me that txtIncumbent.Text will be BOTH the contact_id and the name. So you can use e.g. Mid( txtIncumbent.Text, 1, 8 ) if you know that the contact_id is 8 characters long.

If the id is variable length, use a delimiter (space, colon - whatever looks good and cannot appear in the contact_id) in the text displayed

AddItem rstInc("contact_id") & ":" & rstInc("contact_name")

then use InStr() to find its position.

Good luck

Jonathan C
 
Thank you Jonathan, thats a great idea! i will try it out.
cheers:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top