Entering Only Whole Numbers

J

Jeff L

With your settings the way they are, the user can still enter a
decimal, but once the focus on the textbox is lost the value they
entered will be rounded to the nearest whole number.
 
W

wbohacek

I have a form with a unbound box with format settings of Standard and O
decimals. The unbound box still alows you to enter decimals which I do
not want. How can I prevent a user from accidentally entering decimals,
I only want whole numbers entered.
 
V

Van T. Dinh

The display may look like a whole number but the value is still a decimal
number, though.
 
V

Van T. Dinh

While it may be possible (?) to use InputMask to do this, I avoid InputMask
due to other complications.

I think you need to use one the TextBox Events (perhaps, BeforeUpdate) to
either give the user a wrong input message or to round the value of the
entry automatically.
 
M

missinglinq via AccessMonster.com

"While it may be possible (?) to use InputMask to do this, I avoid InputMask
due to other complications."

The main problem I find with Input Masks occurs when a user clicks on the
control with a mouse rather than tabs into the field. If the insert point is
not at the beginning of the field it tends to mess things up, depending on
the particular mask. This is easily overcome by forcing the insert point to
the beginning of the field by using code like this:

Private Sub MyField_Click()
MyField.SelStart = 0
End Sub

In answer to wbohacek's question, the way to assure that the user cannot
insert a decimal point is to use the input mask 999999. This literally keeps
a decimal from being entered. Just be sure to enter enough 9s to cover the
maximum input size; a mask of 999 will only allow for a three digit number.
 
R

Rick Brandt

missinglinq said:
"While it may be possible (?) to use InputMask to do this, I avoid
InputMask due to other complications."

The main problem I find with Input Masks occurs when a user clicks on
the control with a mouse rather than tabs into the field. If the
insert point is not at the beginning of the field it tends to mess
things up, depending on the particular mask. This is easily overcome
by forcing the insert point to the beginning of the field by using
code like this:

Private Sub MyField_Click()
MyField.SelStart = 0
End Sub

In answer to wbohacek's question, the way to assure that the user
cannot insert a decimal point is to use the input mask 999999. This
literally keeps a decimal from being entered. Just be sure to enter
enough 9s to cover the maximum input size; a mask of 999 will only
allow for a three digit number.

You can also use the KeyPress event of the TextBox to suppress the decimal point
thus eliminating the need for an InputMask...

If KeyAscii = 46 Then KeyAscii = 0
 
W

wbohacek

Rick said:
missinglinq via AccessMonster.com wrote:-
"While it may be possible (?) to use InputMask to do this, I avoid
InputMask due to other complications."

The main problem I find with Input Masks occurs when a user clicks on
the control with a mouse rather than tabs into the field. If the
insert point is not at the beginning of the field it tends to mess
things up, depending on the particular mask. This is easily overcome
by forcing the insert point to the beginning of the field by using
code like this:

Private Sub MyField_Click()
MyField.SelStart = 0
End Sub

In answer to wbohacek's question, the way to assure that the user
cannot insert a decimal point is to use the input mask 999999. This
literally keeps a decimal from being entered. Just be sure to enter
enough 9s to cover the maximum input size; a mask of 999 will only
allow for a three digit number.-

You can also use the KeyPress event of the TextBox to suppress the
decimal point
thus eliminating the need for an InputMask...

If KeyAscii = 46 Then KeyAscii = 0

Thanks for your help. The KeyPress event works great!
 
M

missinglinq via AccessMonster.com

Cool hack, Rick! I often use this form wide, but never thought about using it
for a single text box!

Rick said:
"While it may be possible (?) to use InputMask to do this, I avoid
InputMask due to other complications."
[quoted text clipped - 15 lines]
enough 9s to cover the maximum input size; a mask of 999 will only
allow for a three digit number.

You can also use the KeyPress event of the TextBox to suppress the decimal point
thus eliminating the need for an InputMask...

If KeyAscii = 46 Then KeyAscii = 0
 
Top