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

Last reviewed: May 30, 1997
Article ID: Q132103
The information in this article applies to:
  • Microsoft Access version 2.0

SYMPTOMS

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

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database NWIND.MDB.

  2. Create a new form with the Main/Subform Wizard. Base the main form on the Suppliers table and the subform on the Products table.

  3. Add text box controls for the Supplier ID, Company Name, Contact Name, and City fields to the Main Form.

  4. Add text box controls for the Product ID, Product Name, and Unit Price fields to the subform.

  5. Save the subform as myProductsSubform. Save the main form as MySuppliersMainForm.

  6. Open the MySuppliersMainForm form in Design view

  7. Change the DefaultEditing property to Read Only.

  8. Without using the wizard, add a command button to the form.

  9. 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:

           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).
    
    

  10. Save the MySuppliersMainForm form, and then open the form in Form view.

  11. 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.

  12. 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.

Steps to Work Around Behavior

  1. Open the main form in Design view.

  2. Change the DefaultEditing property to Allow Edits.

  3. 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).

          Macro Name     Macro Actions
          ----------------------------
          mcrReadOnly    SetValue
                         SetValue
    
          mcrReadOnly Actions
          ----------------------------------------------
          SetValue
             Item: DefaultEditing
             Expression: 3
          SetValue
             Item: MyProductsSubform.Form.DefaultEditing
             Expression: 3
    
    

  4. Try changing the entries by repeating steps 11 and 12. Note that this time the form allows edits.

REFERENCES

For more information about the DefaultEditing property, search for "AllowEditing," and then "AllowEditing, DefaultEditing Properties" using the Microsoft Access Help menu.

For more information about macros see the Microsoft Access "User's Guide", version 2, Chapter 24 and 25, "Macro Basics" and "Using Macros with Forms," pages 605-664.


Keywords : FmsSubf kbusage
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : kbfix


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 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.