ACC2: Event Procedure Sets Incorrect Subform Field (131882)



The information in this article applies to:

  • Microsoft Access 2.0

This article was previously published under Q131882
Moderate: Requires basic macro, coding, and interoperability skills.

SYMPTOMS

When you use an event procedure to set a value in a subform's recordset, Microsoft Access writes the value to the incorrect field. That is, it writes the value to a control bound to the field specified in the subform's LinkChildFields property rather than to the recordset field specified in the event procedure.

CAUSE

The subform does not have a control that is bound to the field that the event procedure sets.

STATUS

Microsoft has confirmed this to be a problem in Microsoft Access version 2.0. This problem no longer occurs in Microsoft Access version 7.0.

RESOLUTION

Add a control that is bound to the field that the event procedure sets to the subform.

If you do not want the control to be displayed, you can hide it using one of the following methods:
  • If the subform's DefaultView property setting is Single Form, set the control's Visible property to No.
  • If the subform's DefaultView property setting is Datasheet, open the subform in Datasheet view independently of the main form and reduce the column width of the control to 0 (zero). To reduce the column width to 0, choose Column Width from the Format menu, and then type "0" (without the quotation marks) in the Column Width dialog box.
  • Add an event procedure to the subform's OnLoad property that sets the control's ColumnHidden property to True (-1). For example, set the subform's OnLoad property to the following event procedure:
          Sub Form_Load ()
            Me![My bound control].ColumnHidden = -1
          End Sub
    						

MORE INFORMATION

Steps to Reproduce Problem


  1. Open the sample database NWIND.MDB.
  2. Open the Orders Subform form in Design view.
  3. If the field list is not displayed, from the View menu, choose Field List. Drag the Order ID field from the field list to the subform's detail section.
  4. Delete the Product ID field from the Orders Subform form.
  5. Add an unbound combo box and set the control's properties as follows:
          Name: Product_Combo_Box
          RowSource: Products
          ColumnCount: 4
          ColumnWidths: 0 in; 0 in; 0 in; 1 in
          BoundColumn: 1
    						
  6. Set the combo box's AfterUpdate property to the following event procedure:
          Sub Product_Combo_Box_AfterUpdate ()
             Me![Product ID] = CLng(Me![Product_Combo_Box])
          End Sub
    						
  7. Save and close the Orders Subform form.
  8. Open the Orders form in Form view.
  9. Add a new record to the Orders Subform form by selecting a value from the Product_Combo_Box combo box. Note that Microsoft Access writes the value you select in the incorrect field. That is, the value appears in the Order ID field rather than in the Product ID field.

Modification Type:MajorLast Reviewed:7/5/2002
Keywords:kbbug kbusage KB131882