Do math between a report and subreport

Posted on 2004-11-02
Medium Priority
Last Modified: 2011-04-14
Can I do math on values in a report added to values in a subreport?

Heres an example of what I have now:

                                          (sub Rpt column)

Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)
Jeff Smith,        250.00,           (10.00)
Jane Doe,         500.00             (       )

Totals              850.00                              <<main report footer

How can i put the (demo) total at the bottom of the main report, and add commissions to (Demo) and display as a column.

                                         (sub Rpt column)

Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)     120.00
Jeff Smith,        250.00,           (10.00)     260.00
Jane Doe          500.00            (        )     500.00

Totals              850.00              30.00      880.00

Any help would be greatly appreciated, thanks.

Question by:NDSgroup

Expert Comment

ID: 12479512
putting a field in the footer with Sum([Demo]) doesn't work?

If you look at the properties of the existing sum of commissions and modify it accordingly you ought to be fine.
LVL 58

Accepted Solution

harfang earned 750 total points
ID: 12480459
If curComm and curDemo are currency fields in the table, it is easy:
* Add a new text box for the next column with "= curComm + curDemo" as control source
* Create a report footer on the subreport and ...
* Add a new text box for the demo total with "= Sum(curDemo)"   <--- txtSumDemo
* Add a new text box for the TOTAL with "= Sum(curComm + curDemo)"   <--- txtSumCommDemo

Now, for a reason not entirely clear to us, you want to show the total in the main report, not as a footer of the subreport...
* Add a text box on the main report with "= subSubReportName!txtSumDemo"
* Add a text box on the main report with "= subSubReportName!txtSumCommDemo"

Note: the name "subSubReportName" is the name of the subreport *control* not necessarily the name of the subreport.
Note: you can naturally hide the subreport's footer when you are done debugging.
Note: For the calculation of curComm + curDemo, you could do this in the query on which the report is based.

So, "Can I do math on values in a report added to values in a subreport?"
Not really, but the main report has access to all controls of the subform, containing the last usage of each section.

Good luck with your project!

Expert Comment

ID: 12486561
If what they have suggested doesn't work, consider reworking your report layout. If there is basically a 1-to-1 relationship between the two recordsets (i.e. if for each client record there is only one demo record), then you should be able to create a single query which contains all of the data that you need. Then you can redo your report so that there are no sub-reports to complicate matters.

If there are more than one demo record per client record, you can still probably set things up in this way, but it gets a little more tricky. You would have to design a query which first sums up the Demo values for each client, then create a second query which combines the rest of the fields with the summed Demo data.  Queries like these are not my forte (yet), however, I have designed many reports with subreports and so on, and am slowly discovering that report design is a whole lot easier if you can possibly set up the queries to provide you with a single recordset.

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

LVL 58

Expert Comment

ID: 12492048
> report design is a whole lot easier if you can possibly set up the queries to provide you with a single recordset
Very true.

This works with nested information. For example (pseudo report-printing code)

for each order
   print order header
   for each order detail
      print row


for each department
   for each month
      for each salesperson
         for each sale
            print row

But if you have more than one internal loow, you will need subqueries, as in:

for each employee
   print employee sheet
   for each employee property
      print property
   for each job change
      print job title
   for each year
      print salary overview

The question here is rather: does the subform's report footer information really need to be printed on the main report? It seems more logical and it is easier to place total fields in the same report as the data...

Cheers :)

Author Comment

ID: 12537936
the reason I need to do it the way i described is as follows:

SalesReps make sales, and earn a commission on the sale.

Canvassers make demos, and earn a dollar amount if the demo becomes a sale for the SalesRep.

marketing managers can make demos, and they get a commission on any sale that he or his canvassers make a demo for.

so the marketing manager can make a commission and a demo amount if he makes the demo that becomes a sale, otherwise he just makes a commission if one of his canvassers made the demo.

the problem is that my design dosent allow for a query that will show the marketing manager, the canvasser, weather or not the marketing manager gets a demo amount, how much the sale was for, and any commissions made all on the same one.

what i did was make a report that shows all the marketing mamagers commissions on sales that he or his canvassers demoed, and then made subreports that show the demo amounts the marketing manager should get(demos(appointments) are connected to clients, not sales).  Then i placed the subreport in the detail of the main report. Then i used a text box and some code to add the demo amount to the commission amount to get a total commission on the sale using
I used the IIf(IsError part because the marketing manager wont get a demo on every client that he gets sale commissions on, so sometimes that "row" on the report wont contain anything in the subreport and the math woulld generate an #Error on the report, now if there is no info it places a 0 there instead so I can add it.

then i was able to use a copy of the above text box and make it not visible and make it keep a running sum so that i can place an =Sum in the main report footer to get a grand total.

it's a convoluted process, but it gets the job done, and the client wants the layout to be very clean:

Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)     120.00
Jeff Smith,        250.00,           (10.00)     260.00
Jane Doe          500.00            (        )     500.00

Totals              850.00              30.00      880.00


Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)     120.00
Jeff Smith,        250.00,           (10.00)     260.00
Jane Doe          500.00            (        )     500.00
Totals              850.00                            880.00

the latter of the two examples is what would happen if i placed the demo total in the footer of the subreport and was just not acceptable.

So thanks for the input, I always learn something new every time I come here.

I think i have to give it to harfang because
 "Not really, but the main report has access to all controls of the subform, containing the last usage of each section."
was what sent me on the path to figuring out the math i needed.

LVL 58

Expert Comment

ID: 12541343
Well, glad you could make it work.

As for your very  last example of layout, it just seems strange not to put *all* totals in the subreports footer. They could all be computed there, at least it looks that way. This would also work if the columns were actually in different subreports, all having the same number of rows...

Anyway, good luck!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question