Editing Mainform and Subforms Simultaneously

  • Thread starter Janice Walker via AccessMonster.com
  • Start date
J

Janice Walker via AccessMonster.com

I have a Mainform with subforms on it. The main form is "read Only" for
browsing purposes. When the User reaches a record to edit, there is a
"edit button" to edit the record.

I've tried the following code but it doesn't work. It only makes the main
form editable but not the subform....

Forms![FRM_Profile]![Sub_Profile].Form.AllowEdits = True
Forms![FRM_Profile]![Sub_Profile].Form.AllowDeletions = True
Forms![FRM_Profile]![Sub_Profile].Form.AllowAdditions = True

Dim ctlTemp
For Each ctlTemp In Me.Controls
For Each ctlTemp In Me.Controls
If ctlTemp.ControlType = acSubform Then
ctl.AllowEdits = True
Else
ctl.AllowEdits = True
End If
Next ctlTemp

Is there a good solution to this problem? Is my code correct?

Thanks!!
Janice
 
M

Marshall Barton

Janice said:
I have a Mainform with subforms on it. The main form is "read Only" for
browsing purposes. When the User reaches a record to edit, there is a
"edit button" to edit the record.

I've tried the following code but it doesn't work. It only makes the main
form editable but not the subform....

Forms![FRM_Profile]![Sub_Profile].Form.AllowEdits = True
Forms![FRM_Profile]![Sub_Profile].Form.AllowDeletions = True
Forms![FRM_Profile]![Sub_Profile].Form.AllowAdditions = True

Dim ctlTemp
For Each ctlTemp In Me.Controls
For Each ctlTemp In Me.Controls
If ctlTemp.ControlType = acSubform Then
ctl.AllowEdits = True
Else
ctl.AllowEdits = True
End If
Next ctlTemp

Is there a good solution to this problem? Is my code correct?


Code is not correct.

I assume the duplicated For Each statement is a typo,
otherwise you should have gotten a compile error. To avoid
us debugging typos, you should Copy/Paste your code instead
of retyping it.

The If and the Else statement both do the same thing. Then
Else and its statement should be removed.

The big problem is that you are trying to set the property
on the subform control instead of the form object.
ctl.FORM.AllowEdits = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top