ACC: List Box Column Property Gets Incorrect Row Information (109827)
The information in this article applies to:
- Microsoft Access 1.0
- Microsoft Access 1.1
- Microsoft Access 2.0
- Microsoft Access for Windows 95 7.0
- Microsoft Access 97
This article was previously published under Q109827
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you select a row from a multicolumn list box or combo box, controls
that reference the Column property of the list box or combo box retrieve
data from a different row in the list box or combo box.
NOTE: A list box may appear to work as you want it to, but when you bind
the list box, it will exhibit the same behavior as a combo box.
CAUSE
The list or combo box's BoundColumn property does not point to a field
with unique values.
RESOLUTION
The list 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 will return 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 will return 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, the
behavior will not occur because the Description column contains unique
values.
Another way to resolve this behavior would be to add a Counter field (or
AutoNumber field in Microsoft Access 7.0 and 97) to the underlying table,
and then use the Counter field (or AutoNumber field)for the BoundColumn
property.
In Microsoft Access 7.0 and 97, the following code can be added to the
AfterUpdate property of the combo box.
Me![Stock Number] = _
Me![Manufacturer].Column(1, Me![Manufacturer].ListIndex)
Me![Description] = _
Me![Manufacturer].Column(2, Me![Manufacturer].ListIndex)
NOTE: If you use this code, remove the expressions that are assigned to
the ControlSource properties of the Stock Number control and Description
control.
In Microsoft Access 7.0 and 97, the ListIndex property of the combo box
or list box can be used as a pointer to the correct row in the combo box or
list box. Non-unique columns in a combo box or list box can be resolved by
setting the BoundColumn property to 0 (zero). This will allow a text box on
a form to be populated with, for example, a value in combox.column(1) when
no columns with the combo box contain unique values.
REFERENCES
For more information about creating combo boxes, search the Help Index
for "creating combo boxes," or ask the Microsoft Access 97 Office
Assistant.
Modification Type: | Major | Last Reviewed: | 5/6/2003 |
---|
Keywords: | kbprb KB109827 |
---|
|