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!

Limit Text Box to only accept numbers

Status
Not open for further replies.

Harr777

Programmer
Sep 25, 2003
71
0
0
US
Hi,

I have several text fields that are set to either number or currency data types. I want the fields to only accept number entries. When the user types in text, nothing happens.
Any know how I could do that?
Thanks
 
You could try using the On Key Press command to check if the key pressed is a numeric key or not, like this:

If Not IsNumeric(Me.TextBox1) Then
'code to delete the Text entry
End If

but i've had problems with this, as editing the Field highlights the entire entry which means that every time a key is pressed it highlights the current text, so that when you press another key it overrides it, (if that makes sense!)

Good luck with it.

hope it helps,

muzz
 
You should try using the Input Mask property for the field.

There are a few different options that you will have with this property on how to handle this, your best bet is to read about Input Mask first in the help if you don't have any experience with them.

Regards,
gkprogrammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top