percentage=1000 instead of 100

N

nydia

I have a table that will keep track of production rate. I
want the rate to be in a % format. I put the data type as
%, but when i type in 100, the field should be 100% and it
is coming out 1000%, how can i fix this??
 
A

Allen Browne

Enter the percent sign, i.e.:
100%
or just:
1

If you want to have the entry divided by 100 when no percent sign has been
typed, you could copy the function below into a standard module (in the
Modules tab of the Database window). Then set the AfterUpdate property of
your text box to:
=MakePercent([NameOfYourTextboxHere])

--------------------code begins-------------------------------
Function MakePercent(txt As TextBox)
On Error GoTo Err_MakePercent
'Purpose: Automatically divide text box value by 100 if
' there's no percent sign.
'Usage: Set text box's AfterUpdate property to:
' =MakePercent([MyTextBox])

If Not IsNull(txt) Then
If Right(txt.Text, 1) <> "%" Then
txt = txt / 100
End If
End If

Exit_MakePercent:
Exit Function

Err_MakePercent:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_MakePercent
End Function
-----------------------code ends-------------------------------
 
T

Tim Ferguson

when i type in 100, the field should be 100% and it
is coming out 1000%, how can i fix this??

The "standard" approach is to remember that 100% is another way of writing
1.0 -- it expects you to enter and store a fraction (for example, "0.5" or
"55%"), but is easier to do maths with.

An alternative approach is to enter and store the number of 'percents' and
use the UI to point out the difference. One way is to use a display format,
for example "0\%" (note the backslash tells Access to use the % char,
rather than attempting to format the number as a percentage, i.e. by
dividing it by 100). You can then type "75" into the text box and it will
say "75%". If you prefer (I do...), you can also put a label to the _right_
of the text box on the form or report with a "%" as the caption, so it
looks right.

Hope that helps


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top