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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Text box as Percent

Status
Not open for further replies.

qlan

MIS
Feb 10, 2005
84
US
Hi
I have a field name "SalesProbability" and my datatype is int. On my form I formatted as Percent so it would show "%" at the end. If I enter 20, it will give me 2000%. In order to show 20%, I have to enter .2. Is there a way that I could get 20% by typing 20 instead of .2? Please advise. Thanks so much!
 
That is because 20% is actually .20. If you want to enter 20 and have it show as 20%, you will have to devide the value by 100 when it is entered. You can add the code in the AfterUpdate event like this...

Code:
MyTextbox.Text = MyTextbox.Text/100
 
How are ya qlan . . .

The percent format [blue]displays directly in percent[/blue] (1 = 100%, 0.2 = 20%). [blue]hneal98[/blue] has the code.

Calvin.gif
See Ya! . . . . . .
 
I still don't have it work. Pleas Help!
I have Text Box: Text115. Therefore, After Update, if I do Text Box.Text115 = Text Box.Text115/100. It gives me an error that is it can't find macro. If I do Text115/100, if I enter 20, I will get 2000%. One thing confused me even more is that if 20 gives me 2000%, if I enter .2, I should get 20%. However, it gives me 0.00%. Please advise.

Thanks so much!

 
The AfterUpdate code should be something like this:
Code:
Me.Text115 = Me.Text115 / 100
and, the text box should be formatted as Percent

Si hoc legere scis, nimis eruditionis habes
 
It should be

Code:
Me.Text115.Text = cint(Me.Text115.Text) / 100

I believe you are having the problem becuase the text box is normally a text character instead of a number. The above will convert it to an integer, or you can use cdbl to convert it to a double, etc.
 
or:
Code:
[blue][Text115] = [Text115] / 100[/blue]

Calvin.gif
See Ya! . . . . . .
 
I am so sorry for being so dumb :-(
My after update is
Me.Text115 = CInt(Me.Text115) / 100
and my data type is float. I changed it to many different data types; however, I still could not get it right.

I did some tests by instead of divided by 100, I multiplied by 100 and the result I got is correct based on multiplicaton. However, when I changed it back to divided by 100, it never work right. For example, if I enter from 0 to 50, I will get 0.00%.
From 51 to 149, I will get 100%.
From 150 to 250, I will get 200%, etc.

Please advise. Thanks so much!
 
copy this into your code...

Code:
Private Sub Text115_AfterUpdate()
 Me.Text115 = Me.Text115 / 100
End Sub
 
Hi,
Doesn't matter I used with or without conversion functions, it still is not working. I used

Private Sub Text115_AfterUpdate()
Me.Text115 = Me.Text115 / 100
End Sub
OR
Private Sub Text115_AfterUpdate()
Me.Text115 = CBool or CByte, or CInt, or SLng, or CVar (Me.Text115) / 100
End Sub

Doesn't matter what I did with my codes, it always thinks as an INTEGER.

I think the problem is that my database is a SQL Server. In Access, the table where I get the field name "SaleProbability" is a linked table from the SQL Server. It doesn't matter what my datatype in SQL Server. I tried datatype as INT, float, decimal, etc. In Access, because it is a linked table, the datatype here become Number with Field Size as a "Long Integer". I tried to change the Field Size to Float or something else. However, it did not let me save it when it is a linked table. Therefore, no matter what I have in my code, the result I have is always an INTEGER, which means if I enter from 1 to 50, I will get 0.00%.
From 51 to 149, I will get 100% and etc. The problem I am having is the ROUNDING when the field size in ACCESS is a Long Integer. Thanks so much for all of your help.




 
I tried it and it works, so I am not sure what is going on. You can try using \ instead of /, but I believe \ is for integer anyway.

did you set the textbox format?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top