textbox accepts numbers only (1 Viewer)

me1258

Registered User.
Local time
Today, 08:30
Joined
Apr 6, 2004
Messages
37
HI here is a crazy simple question I don't seem to be able to figure out or find an answer to. I have a program I am making in Access 2003. On the form I have a text box it is used to display the number of tickets sold. I want the user to be able to click in the textbox and enter a number. This all works fine BUT the user can still also enter letters. How do I set the text box so it will respond to numbers only. I would imagine that this would be the on key press code and some how detect the Ascii code to limit it to the integers 0-9 only but I just can figure out the code.
Thanks
:confused:
 

mhartman

Dr. Data
Local time
Today, 06:30
Joined
Jun 5, 2006
Messages
442
Set the Format property of your box to General Number.....
 

me1258

Registered User.
Local time
Today, 08:30
Joined
Apr 6, 2004
Messages
37
Thanks for the quick reply.
I tried that but the txt box still accepts letters... when i do that or even the validation rules it will accept the letters then send up an error box. I want to prevent the user from even using anything but the key pad and the numbers at the top. So if that txtbox had the focus if I pushed a letter it would do nothing.
Thanks
 

Wiz47

Learning by inches ...
Local time
Today, 09:30
Joined
Nov 30, 2006
Messages
274
Thanks for the quick reply.
I tried that but the txt box still accepts letters... when i do that or even the validation rules it will accept the letters then send up an error box. I want to prevent the user from even using anything but the key pad and the numbers at the top. So if that txtbox had the focus if I pushed a letter it would do nothing.
Thanks

I'm guessing that you have that field in the table set for text. Change that to number and then specify something like integer. Then when a non-number is entered in the box, a warning msgbox will be called.
 

me1258

Registered User.
Local time
Today, 08:30
Joined
Apr 6, 2004
Messages
37
Hay I figured it out. I know I had done it a while back but couldn't remember how I did it. Here is the code I am using in the Key down even for the txt box

Code:
Private Sub txtCarCount_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57
Case 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, vbKeyDelete, vbKeyBack, vbKeyReturn
' this seperates the case statements. This is an access bug and making
' it do the  x= y then it defeats the bug
x = y

Case Else
' flushes the key buffer by setting it back to null
KeyCode = 0
End Select

End Sub
[code]

Thanks for the quick reply
 

Wiz47

Learning by inches ...
Local time
Today, 09:30
Joined
Nov 30, 2006
Messages
274
Thanks for posting your solution. That will help someone in the future with a similar problem. (well ... as long as they use the search feature) :)
 

Thales750

Formerly Jsanders
Local time
Today, 09:30
Joined
Dec 20, 2007
Messages
2,061
Thanks for posting your solution. That will help someone in the future with a similar problem. (well ... as long as they use the search feature) :)


Or Google search it, as the case may be.

Thanks from me as well.
 

Thales750

Formerly Jsanders
Local time
Today, 09:30
Joined
Dec 20, 2007
Messages
2,061
The above code allows special charactors.

How would you go about forcing it to reject these special charactors.

In otherwords Shift Numbers.
 

Users who are viewing this thread

Top Bottom