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!

combo box index

Status
Not open for further replies.

DebbieCoates

Programmer
Oct 2, 2007
23
0
0
GB
i am using the following proceedure to fill a combo box on my form.

Public Sub FillCombo(objComboBox As ComboBox, strSQL As String, strFieldToShow As String, Optional strFieldForItemData As String)

Dim rs As New ADODB.Recordset 'Load the data
Set rs = GetRecordset(strSQL)

With objComboBox 'Fill the combo box
.Clear
If strFieldForItemData = "" Then
Do While Not rs.EOF '(without ItemData)
.AddItem rs.Fields(strFieldToShow).Value
rs.MoveNext
Loop
Else
Do While Not rs.EOF '(with ItemData)
.AddItem rs.Fields(strFieldToShow).Value
.ItemData(.NewIndex) = rs.Fields(strFieldForItemData).Value
rs.MoveNext
Loop
End If
End With

rs.Close 'Tidy up
Set rs = Nothing

End Sub

I call it like this

Call FillCombo(cboCountry, "Select CountryID , Country from T_Country", "Country", "countryID")

the table I am calling has 4 entrys per country

county1d, countryname
1 england
2 ireland
3 scotland
4 wales


I would expect the countryId to be the same as the index in the subform, but for some reason the indexing is starting at 0, can anyone help
 
combo box indexes start at ZERO not 1

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top