Format a percent

W

Wendymel

I am trying format a numeric field as percent. My problem is similar to the
posting "Format number field to show percent" by "Kalen" posetd on 1/23/2009.

I have a numeric field named PROJPercComp. I have formatted it as percent
with 0 decimal places.

I want the numbers entered by the user in this field to show as anything
from 1% to 100%. No decimals.

This field is used in a form called frmProjectEntry. It is bound as a source
to a text box called PercCompleted. I used the code suggested by Clifford
Bass in the above mentioned posting. It is:

If Not IsNull(controlname) And Right(controlname, 1) <> "%" Then
controlname = controlname / 100
End If

My version of the After Update code looks like:

If Not IsNull(PercCompleted) And Right(PercCompleted, 1) <> "%" Then
PercCompleted = PercCompleted / 100
End If

What is happening is that if the user enters a number of 50 or less, the
value in the field defaults to 0%. It the user enters a number of 51 to 100
then the value in the field defaults to 100%.

I just want the values to be as entered. No decimals, no rounding. If a
user enters a value of 42 then I want the field to read 42% etc.

Please help!
Thanks,

Wendy
 
D

Dirk Goldgar

Wendymel said:
I am trying format a numeric field as percent. My problem is similar to
the
posting "Format number field to show percent" by "Kalen" posetd on
1/23/2009.

I have a numeric field named PROJPercComp. I have formatted it as percent
with 0 decimal places.

I want the numbers entered by the user in this field to show as anything
from 1% to 100%. No decimals.

This field is used in a form called frmProjectEntry. It is bound as a
source
to a text box called PercCompleted. I used the code suggested by Clifford
Bass in the above mentioned posting. It is:

If Not IsNull(controlname) And Right(controlname, 1) <> "%" Then
controlname = controlname / 100
End If

My version of the After Update code looks like:

If Not IsNull(PercCompleted) And Right(PercCompleted, 1) <> "%" Then
PercCompleted = PercCompleted / 100
End If

What is happening is that if the user enters a number of 50 or less, the
value in the field defaults to 0%. It the user enters a number of 51 to
100
then the value in the field defaults to 100%.

I just want the values to be as entered. No decimals, no rounding. If a
user enters a value of 42 then I want the field to read 42% etc.


From the sound of it, your field size (in the table design) is set to Long
Integer, or maybe Integer or Byte. These are whole-number types, and so
can't hold fractional values. Change the field size to Single or Double.
These are floating types, which are suitable for the Percent format.
 
W

Wendymel

You are absolutely right! It was set as a Long Integer. I changed it to
Single and everything works just fine.

Thanks again!

Wendy
 
A

Al Campagna

Wendy,
I have a numeric field named PROJPercComp. I have formatted it as percent
with 0 decimal places.
Do you mean that you did this on the form?
What data type did you make PercCompleted in your table?

Sounds like you made PercCompleted either a Byte, or Integer, or Long
type.
These types do not allow for decimal values.

Given a Percent formatted field... in order to display 45%, the value
stored in PercCompleted field would be .45.
If your data type is one of the above, it sees the .45 and, since it is
incapable of handling decimal values, rounds down to 0 (or .55 rounds up)

Change your PercCompleted type in your table to Single, and your setup
and code should work.

Note:
If Not IsNull(PercCompleted) And Right(PercCompleted, 1) <> "%" Then
PercCompleted = PercCompleted / 100
End If

--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
F

Fred

Hello Wendy,

If you were dealing with percentage on a mathematical basis, there would be
more question. Percentage is the result of a mathematical operation between
two numbers. It is also often ambiguous / undefined without some verbage
clarifying the intention. (e.g. "what percentage is A of B") For the table
design, simply going to percent formatting does this calculation with the
presumption that the verbage is the above, that "A" is your entered number,
and that "B" is one.

From your post it looks like just entry and display of a number. To make
a point, you could even use a text field, and have your code append a % sign
(if not on already) or even just put the % in the form display rather than in
the table.

With your current situaiton, I'm guessing that your field type is is an
integer and that if you change it to "single" etc. that your method will
work.


To make clarify a point, if this is just a matter of entering and
displaying,
 
A

Al Campagna

Wendy,
My first email dealt with the percent problem you're having...
I meant to add a note about your AfterUpdate code, but inadvertently
sent the email before I had done that.
If Not IsNull(PercCompleted) And Right(PercCompleted, 1) <> "%" Then
PercCompleted = PercCompleted / 100
End If

Given a Single type field, formatted as Percent, and Decimal places = 0,
the only AfterUpdate code you need is...
PercCompleted = PercCompleted / 100
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
W

Wendymel

I have an update to this question.

This solution worked up until this week when we upgraded to Access 2007.
Now I am having the exact same problem described above (and probably more
that I don't even know about yet).

Please help......again !

Thanks,

Wendy
 
Y

yamakamiã„ã‚‹ã‹

watasihaã€
dousitaraitibann,

iinodesyouka?!!

ç§ã¯ã€ã©ã†ã™ã‚Œã°ä¸€ç•ªè‰¯ã„ã®ã§ã—ょã†ã‹ï¼Ÿï¼Ÿï¼ï¼ï¼

家庭をã€æŒã¤ã“ã¨ãŒã€ã„ã„ã°ã‹ã‚Šã¨ã¯ã€é™ã‚Šã¾ã›ã‚“ã­ï¼Ÿï¼ï¼

諦ã‚ãŸãã¯ã€ç„¡ã„ã§ã™ã­ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼


ç§ã¯ã€é«˜æ ¡ã—ã‹ã€å‡ºã¦ã„ã¾ã›ã‚“ï¼ï¼

証人探ã—?ï¼
æ€ã„出ã—ã¾ã—ãŸï¼ï¼ï¼

カラオケã ãƒ¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼â™ªâ™ª

椿ã¡ã‚ƒã‚“☆
ã ã£ãŸï¼ï¼
ã§ã‚‚今ã¯ã€å±±ç¥žã„ã‚‹ã‹ã¡ã‚ƒã‚“ã§ã™ã‚ˆï½žï½žï½žï¼ï¼ï¼

ç§ã¯ã€ä»Šã€ä¼‘憩中ã§ã™ã‹ã‚‰ã€ä½•æ•…ã§ã™ã‹ï¼Ÿï¼Ÿï¼Ÿï¼ï¼ï¼

ã©ã†ã„ã†ã“ã¨ï¼Ÿï¼ï¼

大阪ã«ã€ã¯ãªãƒã‚¨ãŒã€ã„ã¾ã™ã‚ˆï½žï½žï½žâ˜†

dousureba,

minasannno,

tokoroni,

ikukotoga,

dekimasuka??!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


watasiwa,
 

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