I have placed several unlinked subreports in an unbound report’s Report Header. Each subreport has two subreports. I’m trying to get the value of the Top property of the first of these sub-subreport controls, but I’m getting inconsistent results. I have tried two different approaches:
#1). Originally, I used this reference in the OnLoad event of the main report:
intSubSubTop = Me.Controls(strSub1).Report.Controls(strSubSub1).Top
This works perfectly when I switch from Design View to Print View, but I get a runtime error (2455: the expression “has an invalid reference to the property Form/Report”) when I open the report from the navigation pane. Why would there be a difference between these two actions?
#2). Then someone suggested I try TempVars, so I placed the following in the OnLoad event of the subreport:
TempVars!SubSubTop = Me.Controls(strSubSub1).Top
Then in the main report’s OnLoad event I have:
intSubSubTop = TempVars!SubSubTop
This approach works sometimes. Other times I get a runtime error 94: Invalid use of Null. It’s as if the OnLoad event of the subreport only sometimes fires before the main report, so the TempVars may or may not exist for use in the main report. Or maybe the issue is that the sub-subreport sometimes has not yet been loaded.
I know that subforms load before their parent form. Is the same not true for reports? At what point would nested subreport properties be available to the parent report? Is there a way to make the subreport wait until the sub-subreport has been loaded before it tries to get its properties?
What do I need to do to make either approach (or another one) work consistently?
(I’m using Access 2010 on Windows 10 Pro)
4