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

When text box has focus, decimal places change. Why? 1

Status
Not open for further replies.

jasonmac

Programmer
Nov 14, 2002
175
0
0
US
Hi everyone. I'm working in Access 97. I have a text box that is populated when a user clicks a command button. When clicked a calculation is done and the value of the text box is set to the result. This all works fine. I have the text box format set to Fixed and the decimal place property to 2. It works. The number is displayed with two decimal places. However, when I click on the text box, it shows all the decimal places until the focus is shifted elsewhere. Can I format the number of decimal places when I perform the calculation?

Thanks in Advance,
Jason
 
Why let the calculation text box have focus. Change its enabled props to no and locked yes.
 
"Why let the calculation text box have focus" - because the user might want to copy the data and paste it elsewhere.

However, jasonmac, instead of assigning the result of the calculaton to the textbox try assigning a string copy of the result.

e.g.

txtMyAnswer = 1/3 ' assigns the value 0.3333333... to the textbox, your formatting of Fixed, 2 makes it display 0.33

whereas

txtMyAnswer = format(1/3,"0.00") assigns the value 0.33 to the textbox.

Now if you need the exta accuracy that 0.333333 will give in later calculations then you will need to both display 0.33 in the textbox and use 0.333333 in the calculation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top