Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate product in group footer 1

Status
Not open for further replies.

tekkyun

Technical User
Oct 23, 2003
122
GB
Can anyone tell me easy method of calculating product of a detail field within Report group footer instead of sum?
eg
UNIT RESULT
A 2
A 4
A 6
Product of Result=48
 
It is possible to calculate product of a detail field within a report. It can be done as follows

In the report design view Place a new text-box (Text1)
Set the Visible Property of the new text-box to False

In the Report Footer Place another text-box (Text2)
Set the Control Source Property of Text2 text box as
=Text1

In the Report VBA Window Place these Lines of Code

Code:
Option Compare Database
Dim Product As Double

Private Sub Report_Open(Cancel As Integer)
    Product = 1
End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Product = Me.Result * Product
    Me.Text1 = Product
End Sub

Regards,
 
In Continuation of my previous post,
You must also place a code to refresh the value of Product each time the Product is displayed in the Footer.

Code:
Private Sub GroupFooter0_Format(Cancel As Integer, FormatCount As Integer)
    Product = 1
End Sub

The is calculate Product afresh for each footer.

Regards,
 
There is no need for code to accomplish this. Add a text box with a control source of:

=Exp(Sum(Log([Result])))

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I checked your above expression, I works great.
Thanks dhookom, way to learn.
Please accept my Star for you.

Only thing I could not figure it out was how to reset the
=Exp(Sum(Log([Result]))) value at the end of each footer?
Its multiplying all.

Regards,
 
In my tests, this expression works exactly like any other total in a group or report Header or Footer. It will only aggregate values from the appropriate section. The Report Footer calculation will include all records from the report. A group section calculation will only aggregate values from the group.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Cool, its working for me too...

tekkyun, Just implement dhookom method, Its simple and easy.

Regards,
 
Sorry I haven't replied as I have been out of the office all day.
Thank you all for your help. I will try out your suggestions tomorrow and get back if I still have a problem.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top