Textbox Format Property question

R

Rob Hofkens

Hello everyone :)

I have a problem with a textbox not showing the value according to the
format property.
I have a simple sample just to show you my problem.
Create a new form put a "Test" textbox in it and set the Format property to
"Currency".
Open the form and type 100 and press enter and you will see the textbox
change it's display to $ 100.00 or in my case ? 100,00.
This is ok and that is what I want.

My problem:
I want to change the value after it's entered.
As a simple sample I am going to multiply the entered value by 10.
To do this I use this code:

Private Sub Test_AfterUpdate()
Me![Test] = Str(Val(Me![Test]) * 10)
End Sub

Now when I open the form and enter 100 I get the right result 1000 but it
doesn't show as $ 1000.00 or in my case as ? 1000,00.

What can I do to show it according the format property ?

Thanks in advance.

Rob.
 
R

Rob Hofkens

I see now that this newsgroup doesn't support the Euro sign so it shows as a
? in 2 lines :(
It looks weird now with these ? so please imagine a euro sign on 2 lines :)
 
B

BruceM

Try using:
Me![Test] = Me![Test] * 10
I may not fully understand the Val and Str functions, but it seems to me you
are using Val to get the numeric value of something that is already a
number, performing the calculation, and then using Str to turn that result
into a variant.
 
R

Rob Hofkens

Ouch !

I made a fundamental mistake of thinking that everything you entered into a
textbox would generate a String variable.
That's why I did the conversions and finaly stored the "1000" as a string
and not as a numeric value.

You solved my problem and I learned something very important for the future
:)

Thank you Bruce !!


BruceM said:
Try using:
Me![Test] = Me![Test] * 10
I may not fully understand the Val and Str functions, but it seems to me
you are using Val to get the numeric value of something that is already a
number, performing the calculation, and then using Str to turn that result
into a variant.

Rob Hofkens said:
Hello everyone :)

I have a problem with a textbox not showing the value according to the
format property.
I have a simple sample just to show you my problem.
Create a new form put a "Test" textbox in it and set the Format property
to "Currency".
Open the form and type 100 and press enter and you will see the textbox
change it's display to $ 100.00 or in my case ? 100,00.
This is ok and that is what I want.

My problem:
I want to change the value after it's entered.
As a simple sample I am going to multiply the entered value by 10.
To do this I use this code:

Private Sub Test_AfterUpdate()
Me![Test] = Str(Val(Me![Test]) * 10)
End Sub

Now when I open the form and enter 100 I get the right result 1000 but it
doesn't show as $ 1000.00 or in my case as ? 1000,00.

What can I do to show it according the format property ?

Thanks in advance.

Rob.
 
B

BruceM

Glad I could help. I had never thought about it, but I can see where "text
box" could be a misleading name for a control that functions as a window to
whatever type of field you use as its control source.

Rob Hofkens said:
Ouch !

I made a fundamental mistake of thinking that everything you entered into
a textbox would generate a String variable.
That's why I did the conversions and finaly stored the "1000" as a string
and not as a numeric value.

You solved my problem and I learned something very important for the
future :)

Thank you Bruce !!


BruceM said:
Try using:
Me![Test] = Me![Test] * 10
I may not fully understand the Val and Str functions, but it seems to me
you are using Val to get the numeric value of something that is already a
number, performing the calculation, and then using Str to turn that
result into a variant.

Rob Hofkens said:
Hello everyone :)

I have a problem with a textbox not showing the value according to the
format property.
I have a simple sample just to show you my problem.
Create a new form put a "Test" textbox in it and set the Format property
to "Currency".
Open the form and type 100 and press enter and you will see the textbox
change it's display to $ 100.00 or in my case ? 100,00.
This is ok and that is what I want.

My problem:
I want to change the value after it's entered.
As a simple sample I am going to multiply the entered value by 10.
To do this I use this code:

Private Sub Test_AfterUpdate()
Me![Test] = Str(Val(Me![Test]) * 10)
End Sub

Now when I open the form and enter 100 I get the right result 1000 but
it doesn't show as $ 1000.00 or in my case as ? 1000,00.

What can I do to show it according the format property ?

Thanks in advance.

Rob.
 

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