Inputting Percentages in Textboxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I am trying to create a textbox that is "input friendly".

Specifically, it is a textbox that displays and stores numbers a percentages.
The user would enter, say "25" and hit tab. 25 would be automatically
recognized as 25% and displayed as 25% on screen.

This is as opposed to entering 0.25 or having to enter the percentage sign.

In Excel you can do this easily by setting the cell format as percentage but
in Access if I set it to "Percentage" format, type 25, it is recognised as
2500%.

JB
 
You can use code in the after update event of the text box that checks the
entered value. If the text is above a particular value (say 1.0) then
replace the value with the value/100.

I think values should be entered as they are to be stored. Enter .25 for 25%
or .75 for 75%.
 
You can set the textbox's format to Percent, and put logic in its
BeforeUpdate event to divide by 100
 
set the textbox's Format property to Percent. add the following code to the
textbox's AfterUpdate event, as

Me!TextboxName = (Me!TextboxName / 100)

substitute the correct name of the textbox control, of course.

hth
 
Yep, that was what I did (AfterUpate event to divide data entered by 100), I
thought there is something I can set in the textbox properties.

I have tried data format (it just adds %).

Thanks for the help.
 
formatting only affects the way a value is displayed, it does not affect the
value itself. 25 percent is 1/4 of 1, or .25, of course. if that's the value
you want stored, either your user must enter that value, as a decimal, or
you must program the system to take the whole number the user enters and
convert it to a decimal. there are no other options that i can think of.

i do think the AfterUpdate solution is easiest for the user. but looking at
Duane's post made me think - if users know that the value is a percent,
you'll probably get some that will enter 25 for 25 percent - which will
convert to 25%, and some will enter .25 for 25 percent, which will convert
to .25% (1/4 of 1 percent, yikes!). to handle both kinds of users, rather
than trying to train folks to "enter it right", you might try

If Me!txtPercent >= 1 Then Me!txtPercent = (Me!txtPercent) / 100

with the above code, someone who enters 25 will get 25%, and someone who
enters .25 will also get 25%.

hth
 
Back
Top