ACC: List Box Column Property Gets Incorrect Row Information

Last reviewed: May 28, 1997
Article ID: Q109827
The information in this article applies to:
  • Microsoft Access versions 1.x, 2.0, 7.0, 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

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 desired, but upon binding 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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create the following table:

          Table: Table1
          ---------------------------
          Field Name: Manufacturer
    
             Data Type: Text
          Field Name: Stock Number
             Data Type: Number
             Field Size: Long Integer
             Indexed: Yes
          Field Name: Description
             Date Type: Text
    
          Table Properties: Table1
          -------------------------
          Primary Key: Stock Number
    
    

  2. View the table in Datasheet view. Add the following data to the table:

          Manufacturer   Stock Number   Description
          -----------------------------------------
          IB Co          1              Mouse
          IB Co          2              Printer
          IB Co          3              Hard Drive
          ComCo          4              PC
    
    

  3. Create the following new form:

          Form: Test1
          Combo box: Manufacturer
    
             ControlSource: <leave empty>
             RowSourceType: Table/Query
             RowSource: Table1
             ColumnCount: 3
             BoundColumn: 1
             Width: 3
          Text box: Stock Number
             ControlSource: =[Manufacturer].Column(1)
          Text box: Description
             ControlSource: =[Manufacturer].Column(2)
    
    

  4. View the form in Form view.

  5. Select the first row in the combo box. Note that the Stock Number and Description boxes correctly display "1" and "Mouse."

  6. Select the third row in the combo box. Note that the Stock Number and Description boxes still display the information from the first row.

  7. Select the fourth row in the combo box. Note that the Stock Number and Description boxes display the correct information for the fourth row.

If you change the BoundColumn property of the Manufacturer list box to 2 instead of 1, the text boxes on the form will display the correct information for all the rows in the list box because the second column contains 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.


Additional query words: duplicate bound column
Keywords : FmsCmbo kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.