Percent problem again

T

TomH

Percent problem again
Hi
I have a form with a percent field. Percent is number and doublein the table.
To show the actual percent, I put this code in the event AfterUpdate:
Prosent.Value = Prosent.Value / 100
This is working when I write new numbers in the field, but when I put the
cursor in the field and edit an existing percent the result is wrong.
Exampel: edit 4 to 5 in 34% ends up with 0,35% when enter.

This little problem drives me crazy. Is there anyone please, who have a
solution?
 
D

Duane Hookom

Either ditch the code entirely and enter your percents as .35 or check the
value before /100.

Me!Prosent.Value = Me!Prosent.Value / IIf(Me!Prosent.Value<1,1,100)
 
T

TomH

My point is that I want to write the percent in the field as you read it.
(35% is to be written as 35%, not 0.35).

Tried your code, but it didnt worked as I hoped.


Thank you for trying.
 
D

Duane Hookom

"didnt worked as I hoped" doesn't give us much to go on since we don't know
your exact code and your results.

If you want additional help, you have to provide more information.
 
T

Tim Ferguson

My point is that I want to write the percent in the field as you read
it. (35% is to be written as 35%, not 0.35).

In that case store it that way! Use an integer (for example, unlesss you
want stuff like 17.5%) in the range 0 to 100. A good clue for your users is
to place a label to the right of the textbox on the form with a "%"
character in it.

When you use the number in your calculations, you put in the factor of 100
then:

TruePrice:= BasePrice * (1 + TaxPerCent/100)

and so on.

B Wishes


Tim F
 
T

TomH

I'll try too explain my problem better:
- When i write a new percentage, e.g. 65.7, the result after enter is 6570
(this is well known). I correct this whit the formula in the event
afterupdate (dividing by 100) so the result end up as 65.7. So far so good.
- But if I edit the 65.7, lets say I shade the 5-digit and write 2 so the
percentage is 62.7 before enter, the result after enter is 0.627.

This mean the field act in two ways after enter, one when writing a new
percentage and one when editing a existing percentage.

What i ned is a code or formula who do this:
IIF(editing a existing percentage; do nothing; ELSE, divide by 100)
Is there any VBA code who identify wheter you write a new numer in a field
or edit it? If so, my problem is solved, if not, i got a unsolvable problem.

Hope this gave more information.
 
D

Duane Hookom

I tested my code and it works exactly as you asked. I entered 65.7 and it
converted to 65.70%. I then changed the 5 to a 2 and the result was 62.70%.

I mentioned "we don't know your exact code" which you seemed to have
ignored. I can't determine why your implementation didn't work while mine
did.
 
T

TomH

Yes sir, youre right, it worked as you said.
I hanged up in the borderline case whom is less than 1. You now, e.g. 0.65
of a million, the users wont be happy when they notice 65%.

I must problably realize it is not possible to make a general code or
formula that handle all cases of the percentage problem.

Thanks anyway for yor help and patience with me.

Regards
 

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

Similar Threads


Top