DebbieCoates
Programmer
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
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