The list box or combo box's
BoundColumn property must point to a field that contains unique values. If the
BoundColumn property does not point to a field with unique values, Microsoft Access returns information for the first row with a matching
BoundColumn value when you select a row in the list box or combo box.
For example, the Type field in the sample table below does not contain
unique values. If the Type field is used for the
BoundColumn property, a text box referencing the second column returns "Apple" rather than "Grape" when you select the third row.
Type Description
-------------------
Fruit Apple
Fruit Orange
Fruit Grape
If you use the
Description column for the
BoundColumn property, this behavior does not occur because the
Description column contains unique values.
Another way to resolve this behavior is to add an AutoNumber field to the underlying table, and then use the AutoNumber field for the
BoundColumn property.
You can also use the
ListIndex property of the combo box or list box
to reference the selected row in the combo box or list box. Microsoft Access sets the
ListIndex property value when an item is selected in a list box or list box portion of a combo box. The
ListIndex property value of the first item in a list is 0, the value of the second item is 1, and so on. The code below refers to the example listed in the "More Information" section of this article. You can add this code to the
AfterUpdate property of the combo box:
Private Sub Manufacturer_AfterUpdate()
Me![Stock Number] = Me![Manufacturer].Column(1, Me![Manufacturer].ListIndex)
Me![Description] = Me![Manufacturer].Column(2, Me![Manufacturer].ListIndex)
End Sub
NOTE: If you use this code, remove the expressions that are assigned to the
ControlSource properties of the
Stock Number and
Description controls.
Note that the
ListIndex property value can be accessed indirectly by setting the
BoundColumn property of a combo box or a list box to 0. If the
BoundColumn property is set to 0, the underlying table field to which the combo box or list box is bound contains the same value as the
ListIndex property setting.