Adding from subreports: how does this work

rhodesengr

Registered User.
Local time
Today, 08:38
Joined
Sep 4, 2007
Messages
14
In previous post, the problem was how to add two numbers from two subreports in a control on the main report. The answer was given as using this syntax:
=[time entries subreport].Form!Total_Labor+[Expense entries subreport].Form!Total_Expenses

This did in fact work for me.

But I have no idea why this works. What I tried at first was:
=Reports![time entries subreport]![Total_Labor] + Reports![Expense entries subreport]![Total_Expenses]

I built this using the expression builder. It returns a #Name? error in the control on the main report. Looks like the difference is ".Form". I can not find an explantion of what .form does in the expression. I can not find a way to use the expression builder to build the version that works. If it matters I am using Access2000.

I am trying to understand all this.
 
PHP:
=[time entries subreport].Form!Total_Labor+[Expense entries subreport].Form!Total_Expenses

is not Access context.

You probably want

=Reports!Total_Labor.Report![time entries subreport]!Total_Labor + _
Reports!Total_Labor.Report![expense entries subreport]!Total_Expenses

Quit using control names with spaces, it make VBA coding more difficult.

Use the expression builder when possible, even though it incorrectly generates references on occassion, i.e. it is not 100% accurate.
 
PHP:
=[time entries subreport].Form!Total_Labor+[Expense entries subreport].Form!Total_Expenses

is not Access context.

You probably want

=Reports!Total_Labor.Report![time entries subreport]!Total_Labor + _
Reports!Total_Labor.Report![expense entries subreport]!Total_Expenses

Quit using control names with spaces, it make VBA coding more difficult.

Use the expression builder when possible, even though it incorrectly generates references on occassion, i.e. it is not 100% accurate.

I appreciaate your reply. If I add Reports! in front, it stops working. The issues was not spaces but where the .Form property comes from. I see no way to get a ferences with a .Form or .Report in the string. You have to add it manually. It is documented but not available in the expressiona builder as far as I can tell.
 
As I posted previously, your posted line, in my opinion, is not proper Access syntax.

A ".form" in a reference means a subform control, that is, you're referencing a subform. Without a form name, one cannot reference a subform on that form, unless the subform is open as a form.

You might be trying to reference a subreport totals.

To reference subreport controls:

Reports![Report Name].Report![subreport name]![subreport control name].

The expression builder, used in a query for construction purposes only, will build a reference with the correct syntax.
 
Again I do appreciate your looking at this. If you look in my original post

=[time entries subreport].Form!Total_Labor+[Expense entries subreport].Form!Total_Expenses

Is some code that worked, sort of. It worked when I ran my file with Access 2000. When I took the file to work where I have access2003. It did not work. I changed the .form to .report and it worked. So you are correct about .form not being proper syntax to reference a subreport even though it worked in the older version of the program.

My real issue is that I can not get the expression builder in either 2000 ro 2003 to build an expression with either .form or .report in a control reference. The second bit of code in my original post was directed copied from the expression builder. Here it is again.
=Reports![time entries subreport]![Total_Labor] + Reports![Expense entries subreport]![Total_Expenses]

I played around my by bit of code that worked and found that if i added the Reports! prefix, it stopped working. It seems that only works if the subreport is open or you you are referencing an outside report, not a subreport.

If you know how to get the expression builder to paste in a reference to a subreport with .Report and not with Reports! such as:

=[time entries subreport].Report![Total_Labor]

I would appreciate knowing how. I don't think the expression builder will do it.
 
Use the expression builder in a query field column or query criteria column. Microsoft really dropped the ball on this. I recall that one could use it anywhere in A97. The expression builder will build Reports![Main reportname].report![time entries subreport]![Total_Labor], not [time entries subreport].Report![Total_Labor].

The reports refers to the reports container, the report refers to a (sub) report control on the specified report.

Of course, forms, subforms, sugsubforms, and reports, etc. have to be open to be referenced. Think about it - what value does a control have on a closed form.

The syntax for referencing subforms/subreports and subsubforms/reports is easy to miss, especially if there are blanks in a control name. Never, I repeat, never, use blanks in a control name. Underscores and Upper/Lower make long control names easy to read.

You can reference any form or report object which is open.

I've had trouble getting subform/sureports to total correctly and have ended up using a subform/subreport for the total. I continually do something incorrect. As a matter of coding practice I use the control record source as the control name - I think that that triggers my problem.
 

Users who are viewing this thread

Back
Top Bottom