Nested Subform References

G

Guest

Access allows up to seven levels of nested subforms. Is it possible to reference down this far (I only need 3 levels, however)?

I am trying to set AllowEdits = False on all forms and subforms. Unfortunately, I can't seem to reference a 3 level deep subform. Is this possible?

ex. Forms!frmMain!sub1!sub2.Form.AllowEdits = False works fine
Forms!frmMain!sub1!sub2!sub3.Form.AllowEdits = False returns a reference error at runtime

Better yet, is there a way to set AllowEdits to False for all open forms and subforms with one routine

Thanks!
 
A

Allen Browne

Add the ".Form" bit to each reference, i.e.:
Forms!frmMain!sub1.Form!sub2.Form!sub3.Form.AllowEdits = False

It would be possible to write a routine that loops through all forms in the
Forms collection, loops through all controls on each form to find those of
ControlType acSubform, and then calls itself recursively to lock/unlock
their subforms as well.

This kind of thing (aircode):
---------------code starts------------------------
Public Function LockEmAll(bLock As Boolean)
Dim frm As Form

For each frm in Forms
Call LockEm(frm, bLock)
Next

Set frm = Nothing
End Function

Private Function LockEm(frm As Form, bLock As Boolean)
Dim ctl As Control

With frm
If .Dirty Then
.Dirty = False
End If
.AllowEdits = bLock
.AllowDeletions = bLock
.AllowAddtions = bLock

For each ctl In .Controls
If ctl.ControlType = acSubForm Then
Call LockEm(ctl.Form, bLock)
End If
Next
End With
End Sub
---------------code ends------------------------

You do realise that this locks even unbound controls? We have found it more
practical to lock individual controls rather than the whole form. This
leaves unbound controls unlocked, and also lets us pass in a ParamArray of
the names of controls that are not to be locked (e.g. for selectively
locking subforms).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Mike Finger said:
Access allows up to seven levels of nested subforms. Is it possible to
reference down this far (I only need 3 levels, however)?
I am trying to set AllowEdits = False on all forms and subforms.
Unfortunately, I can't seem to reference a 3 level deep subform. Is this
possible?
 

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