Calculate Percentage VBA

jsdba

Registered User.
Local time
Today, 15:39
Joined
Jun 25, 2014
Messages
165
I have two numbers, i need to calculate how much percentage of one is the other. E.g
num_1 = 100
num_2 = 10
percent = 10%

Users enter a dollar amount (retainer) and my code should calculate the percent of the total proposal amount.

Actual Code
Code:
Private Sub cmdSubmit_Click()
Dim intProposalTotal As Double '\\if i use interger i get "overflow" error
intProposalTotal = Nz(DLookup("ProposalTotal", "qryPropsalTotalForRetainer", "proposal_id=" & Me.proposal_id), 0)

Me.billing_retainer_percent = myPercentage(Me.txtRetainerAmount, intProposalTotal)
End Sub

Public Function myPercentage(argAmount As Integer, argTotal As Double)
    
myPercentage = Round((argAmount / argTotal) * 100, 0)
    
End Function

billing_retainer_percent is formatted to Percent with 0 decimals. In the actual table Type - Number, Format - Percent, Field Size - Single. What i get is 100% instead of 10%.

Please help.
 
I just tried your function using dummy values. See attached jpg.
Works fine for me. I have no idea what your query is about or the values.
 

Attachments

  • MyPercentTest.jpg
    MyPercentTest.jpg
    35.3 KB · Views: 453
I just tried your function using dummy values. See attached jpg.
Works fine for me. I have no idea what your query is about or the values.

Query calculates sum of fees (number field) and group by proposal_id.

I've changed my textbox "me.billing_retainer_percent" from percent to number with two decimal places. but its gives me about 5 decimal places. How can i round my result to 2 decimal places? E.g 10.50 vs 10.51423
 
I've figured it out. Thanks for the help
 
don't multiply by 100
10% is 0.1
Formating 0.1 as percent will show you 10%
 

Users who are viewing this thread

Back
Top Bottom