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!

Trying to get percentages to calculate right

Status
Not open for further replies.

SoulBrutha23

Technical User
Sep 26, 2001
8
US
I have a text box (textGrade) that is trying to calulate a percentage from totals text box (txtTotal).

Here is the procedure:

Private Sub txtGrade_Enter()
txtGrade = txtTotal / 21
End Sub

So when I run the procedure, either i the answer is 0 or 100%. What did I do wrong?

 
I presume you are using a sub to calculate the percentage because the control is bound. If it is bound I suspect its datatype is set to integer. It can therefore only be 1 or 0 (assuming the calculation is correct, because the datatype will allow much larger numbers, but they will always be rounded).

Another possibility are the properties of the control. If they are set to an accuracy of 0 decimal places it could produce the same result. James Goodman
 
So what should I do to correct the problem and get an accurate answer?
 
You need to check the datatype for the control (in table design view) is set correctly. As default access sets number fields to integer datatype, which would round all values to the nearest whole number (a 1 or 0)

You can actually set its datatype to single, & its format to percentage... James Goodman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top