Microsoft KB Archive/132103

= ACC2: Subform's DefaultEditing Can't Be Changed to Allow Edits =

Article ID: 132103

Article Last Modified on 7/5/2002

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q132103



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



SYMPTOMS
If you have a main form that includes a subform, and you set the main form's DefaultEditing property to Read Only, the subform remains read-only and ignores any attempts to change it to Allow Edits as long as the main form is in Form view.

When you want to protect a form record's information, you can set the form's DefaultEditing property to Read Only. If you need to be able to change this property while the form is in Form view, you can add a command button to your form that resets the DefaultEditing property to Allow Edits.

However, if your form contains a subform, the subform will not allow any user input even when you explicitly change the DefaultEditing property of the subform to Allow Edits.



RESOLUTION
Set the main form's DefaultEditing property to Allow Edits, and add a macro or Access Basic code to the Open or Load event so that it changes the DefaultEditing property to Read Only.



STATUS
This behavior no longer occurs in Microsoft Access version 7.0.



Steps to Reproduce Behavior
 Open the sample database NWIND.MDB. Create a new form with the Main/Subform Wizard. Base the main form on the Suppliers table and the subform on the Products table. Add text box controls for the Supplier ID, Company Name, Contact Name, and City fields to the Main Form. Add text box controls for the Product ID, Product Name, and Unit Price fields to the subform. Save the subform as myProductsSubform. Save the main form as MySuppliersMainForm.</li> Open the MySuppliersMainForm form in Design view</li> Change the DefaultEditing property to Read Only.</li> Without using the wizard, add a command button to the form.</li>  Open the Properties window. Select the OnClick property for the command button, and then click the Build button. In the Choose Builder dialog box, select Macro Builder, create the following macro, and then save it as mcrAllowEdits:

<pre class="fixed_text">      Macro Name      Macro Actions -      mcrAllowEdits   SetValue SetValue

mcrAllowEdits Actions --      SetValue Item: DefaultEditing Expression: 2 SetValue Item: MyProductsSubform.Form.DefaultEditing Expression: 2

NOTE: The mcrAllowEdits macro will change the DefaultEditing property to Allow Edits (2 in Access Basic). </li> Save the MySuppliersMainForm form, and then open the form in Form view.</li> Try changing one of the entries. Note that you cannot do so because the main form is read-only. Try to change entries in the subform. Note that you cannot do so because the subform has inherited the read-only property from the main form.</li> Click the command button, and try changing some entries on the main form. Note that now you can change them because the DefaultEditing property was changed to Allow Edits. Try to change some entries on the subform. Note that you cannot do so because the subform remained Read Only.</li></ol>

Steps to Work Around Behavior
<ol> Open the main form in Design view.</li> Change the DefaultEditing property to Allow Edits.</li>  In the OnLoad property of the main form, create the following macro, and call it mcrReadOnly. This macro will change the DefaultEditing property to Read Only (3 in Access Basic).

<pre class="fixed_text">     Macro Name     Macro Actions mcrReadOnly   SetValue SetValue

mcrReadOnly Actions --     SetValue Item: DefaultEditing Expression: 3 SetValue Item: MyProductsSubform.Form.DefaultEditing Expression: 3 </li> Try changing the entries by repeating steps 11 and 12. Note that this time the form allows edits.</li></ol>

<div class="references_section">