Microsoft KB Archive/131882

= ACC2: Event Procedure Sets Incorrect Subform Field =

Article ID: 131882

Article Last Modified on 7/5/2002

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



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 



Steps to Reproduce Problem
 Open the sample database NWIND.MDB.</li> Open the Orders Subform form in Design view.</li> 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.</li> Delete the Product ID field from the Orders Subform form.</li>  Add an unbound combo box and set the control's properties as follows:

<pre class="fixed_text">     Name: Product_Combo_Box RowSource: Products ColumnCount: 4 ColumnWidths: 0 in; 0 in; 0 in; 1 in     BoundColumn: 1 </li>  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 </li> Save and close the Orders Subform form.</li> Open the Orders form in Form view.</li> 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.</li></ol>

Keywords: kbbug kbfix kbusage KB131882

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.