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
- 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.
- Open the MySuppliersMainForm form in Design view
- Change the DefaultEditing property to Read Only.
- Without using the wizard, add a command button to the form.
- 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).
- Save the MySuppliersMainForm form, and then open the form in Form
view.
- 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.
- 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
- Open the main form in Design view.
- Change the DefaultEditing property to Allow Edits.
- 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
- 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.