ACC: Form Is Editable Even When AllowEdits Property Set to False

Last reviewed: August 29, 1997
Article ID: Q167420
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

SYMPTOMS

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

When you open a Microsoft Access form that has the AllowEdits property set to No (False), you can still edit the fields on that form.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

CAUSE

This behavior occurs if you set the value of a control programmatically in the Current event of the form. It also occurs if you set the value of a control in the Load event of the form. In that case, however, the only record that you can edit is the first record that is displayed on the form.

RESOLUTION

If you need to edit the values of bound fields programmatically in forms that have the AllowEdits property set to False, edit those fields in the RecordsetClone of the form, and not in the form itself.

The following example demonstrates how to create Visual Basic code in the Current event of a form that can change the values of fields in the RecordsetClone of a form.

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Start Microsoft Access and open the sample database Northwind.mdb.

  2. Open the Customers form in Design view.

  3. Set the AllowEdits property of the form to No.

  4. Set the OnCurrent property of the form to the following event procedure:

          Private Sub Form_Current()
          Dim rs As Recordset
          Set rs = Me.RecordsetClone
          rs.Bookmark = Form.Bookmark
          rs.Edit
          ' The following updates the CompanyName field to itself plus the
          ' letter "a".
          rs!CompanyName = rs!CompanyName & "a"
          rs.Update
          End Sub
    

  5. Save the form and open it in Form view. Note that each time you view a record, the letter "a" is appended to the Company Name, but you cannot edit any of the fields on the form.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start Microsoft Access and open the sample database Northwind.mdb.

  2. Open the Customers form in Design view.

  3. Set the AllowEdits property of the form to No.

  4. Set the OnCurrent property of the form to the following event procedure:

          Private Sub Form_Current()
          ' The following updates the CompanyName field to itself plus the
          ' letter "a".
          Me!CompanyName = Me!CompanyName & "a"
          End Sub
    

  5. Save the form and open it in Form view. Note that each time you view a record, the letter "a" is appended to the Company Name, and note that you can also change other fields on the form.

  6. Press CTRL+G to open the Debug window.

  7. Type the following in the Debug window, and then press ENTER:

          ?Forms!Customers.AllowEdits
    

    Note that the property is set to False, but that you are able to edit fields on the form.

If you modify the code in step 4 to programmatically set the AllowEdits property to False (or to True and then back to False), it has no effect; you are still able to edit fields on the form.

REFERENCES

For more information about the AllowEdits property, search the Help Index for "AllowEdits property," or ask the Microsoft Access 97 Office Assistant.

For more information about the RecordsetClone property, search the Help Index for "RecordsetClone property," or ask the Microsoft Access 97 Office Assistant.

Keywords          : kbusage FmsProp FmsEvnt
Version           : 7.00 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb
Solution Type     : kbworkaround


================================================================================


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