Formatting numbers in a TextBox

J

John S. Ford, MD

I have a form with several subforms. Some of the subforms have TextBoxes
for which numeric data will be entered. I'd like to format the way such
data shows up after the user hits <Enter> such that:

1. All decimal places typed in are shown but no terminal zeros are
displayed.
2. All numbers less than 1 show a leading zero.
3. All integer entries do not display a decimal point.

Examples:
If 1.250 is entered, then 1.25 is displayed.
If .25 is entered, then 0.25 is displayed.
If 12.00 is entered, then 12 is displayed (no decimal point).
If 12.0010 is entered, then 12.001 is displayed.

I'm assuming that this can be done by setting the TextBox's "Format"
property but I can't figure out how to do this. Any ideas? Also, what
property settings would I have to set in the underlying table's field that
the TextBox is bound to do this?

I'd also like the final report based on the information entered into the
form to present this data in the exact same format. Would I be able to use
the same Format property in the report's TextBoxes?

Thanks in advance!

John
 
J

JK

Hi John,

Leave the format property empty, set the decimal property to Auto and create
an AfterUpdate event:

Private Sub YrTextBoxName_AfterUpdate()

Me.YrTextBoxName=iif(IsNull( Me.YrTextBoxName), _
Null, Val(me.YrTextBoxName))

End Sub

Regards/JK


|I have a form with several subforms. Some of the subforms have TextBoxes
| for which numeric data will be entered. I'd like to format the way such
| data shows up after the user hits <Enter> such that:
|
| 1. All decimal places typed in are shown but no terminal zeros are
| displayed.
| 2. All numbers less than 1 show a leading zero.
| 3. All integer entries do not display a decimal point.
|
| Examples:
| If 1.250 is entered, then 1.25 is displayed.
| If .25 is entered, then 0.25 is displayed.
| If 12.00 is entered, then 12 is displayed (no decimal point).
| If 12.0010 is entered, then 12.001 is displayed.
|
| I'm assuming that this can be done by setting the TextBox's "Format"
| property but I can't figure out how to do this. Any ideas? Also, what
| property settings would I have to set in the underlying table's field that
| the TextBox is bound to do this?
|
| I'd also like the final report based on the information entered into the
| form to present this data in the exact same format. Would I be able to
use
| the same Format property in the report's TextBoxes?
|
| Thanks in advance!
|
| John
|
|
 
J

John S. Ford, MD

Dear JK,

Thank you very much! That worked exactly the way I wanted it to. I'll have
to look up the Val function to see how it did that.

Take care,
John
 
J

JK

My pleasuer

| Dear JK,
|
| Thank you very much! That worked exactly the way I wanted it to. I'll
have
| to look up the Val function to see how it did that.
|
| Take care,
| John
|
| | > Hi John,
| >
| > Leave the format property empty, set the decimal property to Auto and
| > create
| > an AfterUpdate event:
| >
| > Private Sub YrTextBoxName_AfterUpdate()
| >
| > Me.YrTextBoxName=iif(IsNull( Me.YrTextBoxName), _
| > Null, Val(me.YrTextBoxName))
| >
| > End Sub
| >
| > Regards/JK
| >
| >
| > | > |I have a form with several subforms. Some of the subforms have
TextBoxes
| > | for which numeric data will be entered. I'd like to format the way
such
| > | data shows up after the user hits <Enter> such that:
| > |
| > | 1. All decimal places typed in are shown but no terminal zeros are
| > | displayed.
| > | 2. All numbers less than 1 show a leading zero.
| > | 3. All integer entries do not display a decimal point.
| > |
| > | Examples:
| > | If 1.250 is entered, then 1.25 is displayed.
| > | If .25 is entered, then 0.25 is displayed.
| > | If 12.00 is entered, then 12 is displayed (no decimal point).
| > | If 12.0010 is entered, then 12.001 is displayed.
| > |
| > | I'm assuming that this can be done by setting the TextBox's "Format"
| > | property but I can't figure out how to do this. Any ideas? Also,
what
| > | property settings would I have to set in the underlying table's field
| > that
| > | the TextBox is bound to do this?
| > |
| > | I'd also like the final report based on the information entered into
the
| > | form to present this data in the exact same format. Would I be able
to
| > use
| > | the same Format property in the report's TextBoxes?
| > |
| > | Thanks in advance!
| > |
| > | John
| > |
| > |
| >
| >
|
|
 

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