Inconsistent Results Referencing Nested Subreport Property

gr8dane

New member
Local time
Today, 15:30
Joined
May 27, 2024
Messages
22
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-subreports, but I'm getting inconsistent results. The reference I'm (currently) using in the OnLoad event of the main report is:

Code:
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?

I've tried different variations to no avail. What do I need to do to make it work consistently? At what point would nested subreport properties be available to the parent report?

(I'm using Access 2010 on Windows 10 Pro)
 
If you are trying to get the properties of a sub report inside a second sub report, the syntax might be

Code:
intSubSubTop = Me.Controls(strSub1).Report.Controls(strSubSub1).Report.Top
 
If you are trying to get the properties of a sub report inside a second sub report...
I'm actually trying to get a property of the control that holds the sub-subreport. The Top property of the report inside the control would be 0. In any case, neither code works.
 
In any case, neither code works.
Try creating tempvars. In the open event of the subreport, place the top attribute for the subsubreport control into the tempvar. Then the main report can get the value from the tempvar. You may have to experiment with the event you use to capture the top property.

Maybe you should tell us why you need to do this.
 
Here is a sample that will help you to understand event firing order.

You might want to watch one of the videos first to see how the database works.
 
Try creating tempvars. In the open event of the subreport, place the top attribute for the subsubreport control into the tempvar. Then the main report can get the value from the tempvar. You may have to experiment with the event you use to capture the top property.
Thank you!! That's exactly what I needed. I had heard of TempVars, but had never used them before. It's still a mystery why it acted differently depending on how I opened the report, but I'm not going to worry about it anymore.
 
Actually, I spoke too soon. This only 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? Is there a way to make the subreport wait until the sub-subreport has been loaded before it tries to get its property?
 
Last edited:
Is there a way to make the subform wait until the sub-subform has been loaded before it tries to get its property?

At least in theory, it DOES wait. The order should be sub-sub-form loads, then sub-form loads, then form loads.

The "Invalid use of null" suggests that something is testing a control or property prematurely. But that is a run-time error so you should have notifications enabled while debugging this. If you do, you'll get the error but a particular instruction will also be highlighted. Knowing that will pin-point what could be null because you could see what was being referenced on the right side of the equals sign or what was referenced in the arguments of a function or sub call. And that info about WHERE the error occurs is golden in this circumstance.

Further, when you are stopped for a run-time error, you are in Debug mode. You should be able to hover the mouse cursor over various items to see their values. If anything is "null" (or "nothing" if it was an object pointer), you should see that, too.
 
At least in theory, it DOES wait. The order should be sub-sub-form loads, then sub-form loads, then form loads.
Sorry, I meant to say "...a way to make the subreport wait until the sub-subreport has been loaded..." (I've corrected my post). There's no form involved here. That's why I asked if reports load in the same order. The rest of your post I already know.

In the OnLoad event of the subreport, I have the following:
Code:
TempVars!SubSubTop = Me.Controls(strSubSub1).Top
Then in the main report's OnLoad event I have:
Code:
intSubSubTop = TempVars!SubSubTop
This is the line that gets highlighted when the error occurs.
 
you will get Error when you view the Main report in Report view. use Print Preview view instead.
 
you will get Error when you view the Main report in Report view. use Print Preview view instead.
As I said in my original post, I am viewing the report in Print Preview. All the reports are set to open in Print View. I never use Report View.
 
you can use the following contruct on the Load event of the main report:
Code:
intSubSubTop =  Reports!MainReportName!SubReportName!subsubReport1.Report.Top
 
you can use the following contruct on the Load event of the main report:
Code:
intSubSubTop =  Reports!MainReportName!SubReportName!subsubReport1.Report.Top
So, what are you suggesting I should change in the reference I originally used (note the different style), which didn't work?
Code:
intSubSubTop = Me.Controls(strSub1).Report.Controls(strSubSub1).Top
Also, please note that it's the sub-subreport control, not its report, whose Top property I'm trying to get.
 

Users who are viewing this thread

Back
Top Bottom