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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Percentage of Total 1

Status
Not open for further replies.

AlanJordan

Programmer
Sep 15, 2005
139
US
I have a report that uses groups to create subtotals of each group.

At the end of the report, I have a grand total.

I want to calculate the percentage of each subtotal of the grand total.

I tried the following code, which fails because Access will not allow me to set the focus and it will not allow the assignment with having the focus set.

Interestingly, the function worked once, and then did not work. Perhaps I was in break mode that first time.

Any insights or suggestions will be appreciated.


Code:
Function CalcGroupPercentage()
On Error GoTo err_CGP
    Dim dblNumerator As Double
    Dim dblDenominator As Double
    Report_rptTimeInvested.txtGroupSubtotal.SetFocus
    dblNumerator = CDbl(Me.txtGroupSubtotal.Text)
    Me.txtGrandTotal.SetFocus
    dblDenominator = CDbl(Me.txtGrandTotal.Text)
    
    If dblDenominator <> 0 Then
        CalcGroupPercentage = dblNumerator / dblDenominator
    Else
        CalcGroupPercentage = 0
    End If
Exit Function
err_CGP:
    ErrBox
End Function
 
Okay. I'll leave it in for a while, then I'll delete it.

Thanks again.

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top