How to reference a sub subform allowedits property?

S

sturgel

How can I do the following? I tried just about everyway that would seem
logical but I still get error 438 "Object doesn't support this proerty of
method" or "You entered an expression that has an invalid reference to the
property Form/Report".

I have a subform (subsubform) within another subform on a main form. I am
trying to set the AllowEdits property of the subsubform in the main form
using a module subroutine. I've tried numerous ways to do this but get the
above errors. I am using the following variables for each form:

frmActive = the Main Form
subctl = the Sub Form
subsubctl = the Sub Sub Form (nested subform within subctl)

My last attempt was this:

Forms(frmActive.Name).Controls(subctl.Name).Controls(subsubctl.Name).allowedits

How do you access a subform form within a subform form using variables for
the form objects?

I am trying to do this in a subroutine in a module using the following
nested loops.

For Each subctl In frmActive
If TypeOf subctl Is SubForm Then
subctl.Form.AllowEdits = True <------- WORKS!

For Each subsubctl In subctl.Form
If TypeOf subsubctl Is SubForm Then
subsubctl.Form.AllowEdits = True <---- FAILS!

end if
Next
end if
Next

Can you use the code above to determine a solution?
Thanks!
 
J

John Smith

You need to reference the subform to get to the sub-subform. Try:

subctl.Form.subsubctl.Form.AllowEdits = True

That should work in your code.
 
S

sturgel

Thanks John but that didn't work I get an "Application defined or object
defined error" I even tried:

frmActive.Form.SubCtl.Form.SubSubCtl.Form.AllowEdits and same thing.

This one is a stumper, I tried to get an answer for this before.
Interestingly, you can't drill down to the sub subform in the object browser.
You only get as far as the sub subform control not the form within the
control. Unless there is a way to drill down then I can use that hiearchy to
build a reference to the sub subform allowedits property. Any ideas?
 
J

John Smith

Puzzling, I expected that to be it! In that case maybe you will have to go
back to the fully qualified name, but you need to amend the syntax slightly:

Forms(frmActive.Name).Controls(subctl.Name).Form.Controls(subsubctl.Name).Form.
AllowEdits

Incidentally and just in case, have you checked that the query for the
sub-subform is updateable? If not it will never work!
 
S

sturgel

Thanks again John, still no success. I get the error "You entered an
expression that has an invalid reference to the property Form/Report". The
sub subform query is updateable. The error only happens when there is no
record in the subform or subsubform to display.

When I check th values here is what I get which is correct!

? frmActive.Name
EmployeeAbsenceForm <--- main form
? subctl.Name
AbsencePeriodCtl <---- subform control
? subsubctl.Name
AbsenceDayCtl <--- sub subform control

There has to be a way. Have you tried to do a simple test form?
 
P

PC Datasheet

Try this:

Dim Frm As Form
Dim Ctl As Control
Dim SubCtl As Control
Set Frm = Forms!EmployeeAbsenceForm
For Each Ctl In Frm
If Ctl.ControlType = acSubForm Then
Ctl.Form.AllowEdits = True
For Each SubCtl In Frm.Ctl.Form
If SubCtl.ControlType = acSubForm Then
SubCtl.Form.AllowEdits = True
End If
Next
EndIf
Next
 
M

Marshall Barton

Here's a thought(?). If the subform has no records and
AllowAdditions is False, then the subsubform control does
not really exist in the subform, so you can't set its
properties. (I know this situation arises in subreports so
it may apply here too.)

Since form's don't have the HasData property, try checking
for subctl.Form.RecordsetClone.RecordCount > 0 before
looping through the subsubform's Controls collection.
 
S

sturgel

nameAfter some testing and a hunch, I solved my problem. The solutions was
to make the subform controls the same name as the subform forms name. When I
did this, the suggestion that John had:

Forms(frmActive.Name).Controls(subctl.Name).Form.Controls(subsubctl.Name).Form.AllowEdits = true

Worked!

Thanks John for your help!
 
M

Marshall Barton

Well, I can't pretend to see how that made a difference. I
would have thought the use of the Controls collection would
have been sufficient.

I'll try to keep this whole issue in mind, thanks for
posting your final resolution.
 

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