Combo Box Trouble - TechRepublic
Question
April 2, 2007 at 06:29 AM
carterlangley

Combo Box Trouble

by carterlangley . Updated 19 years, 2 months ago

Hi guys,

Here is code I am using to populate a combo box from the table.

Set cnnConnection = CurrentProject.Connection
Set rstRecordset = New ADODB.Recordset
strSQL = “SELECT * FROM Country ORDER BY Country”
rstRecordset.Open strSQL, cnnConnection, adOpenDynamic, adLockOptimistic
rstRecordset.MoveFirst

With cboCountry
.RowSourceType = “Value List”
Do Until rstRecordset.EOF
.AddItem rstRecordset.Fields(“Country”).Value
rstRecordset.MoveNext
Loop
End With

rstRecordset.Close
Set rstRecordset = Nothing

Now, I would like to be able to store the id field (autonumber field) related to the country name in the table. How do I get that unique id field from the combo box once a user makes a selection? the actual value or name means nothing to me, I need the unique id that identifies that specific selection.

I only want the new record to be added to the table once the user presses a button on the form. so my code will cycle through all the textboxes, etc and gather the necessary to write to the table. only having a problem with the combo box story at present.

This discussion is locked

All Comments