Numbers in a text property.

B

Bob

I have a field "text property"
How can I block the users from entering alphabets?
Only numbers should be allowed.
I don't want to change the field to Number property.

Thanks
Bob
 
J

JSand42737

"Bob" said:
I have a field "text property"
How can I block the users from entering alphabets?
Only numbers should be allowed.
I don't want to change the field to Number property.

Thanks
Bob

Bob

You can use the Control's KeyDown event to check what key is pressed:

Private Sub txtUnitsInStock_KeyDown(KeyCode As Integer, Shift As Integer)
If Not IsNumeric(Chr(KeyCode)) Then KeyCode = 0
End Sub

The above will only allow numbers 0 to 9 - everything else gets cancelled.
 
B

Bob

Thanks
Bob
-----Original Message-----


Bob

You can use the Control's KeyDown event to check what key is pressed:

Private Sub txtUnitsInStock_KeyDown(KeyCode As Integer, Shift As Integer)
If Not IsNumeric(Chr(KeyCode)) Then KeyCode = 0
End Sub

The above will only allow numbers 0 to 9 - everything else gets cancelled.


--

Jon

www.applecore99.com - Access Tips and Tricks

.
 
B

Bob

Thanks
But, the Tab button, the numbers on the right side on the
keyboard doesn't work. Can you fix that?
Thanks
 
B

Bob

Maybe I should change the properties to Number?
The reason I changed it to Text, because I want to be able
to use number like this
0005
0123
000954
55013
What's you solution?
Thanks again.
Bob
 
J

JSand42737

"Bob" said:
Thanks
But, the Tab button, the numbers on the right side on the
keyboard doesn't work. Can you fix that?
Thanks

Bob

Try this:

Private Sub txtUnitsInStock_KeyDown(KeyCode As Integer, Shift As Integer)
If Not IsNumeric(Chr(KeyCode)) _
And (KeyCode <> 9) And (KeyCode < 96 And KeyCode > 105) _
Then KeyCode = 0
End Sub
 
J

JSand42737

"Bob" said:
Maybe I should change the properties to Number?
The reason I changed it to Text, because I want to be able
to use number like this
0005
0123
000954
55013
What's you solution?
Thanks again.
Bob

Bob

Whilst you could use the Format property of the control to display leading
zeroes for numeric fields, it looks like this won't work with your data, as
there is no consistent length to the data.
 
J

Joe

Thanks Jon
Let me change my question.
This field must be at least 4 digits long, so the zeros
will only had to be added until it reaches 1000. after
1000 I don't need any zeros.
Any solution?
Thanks
Joe
 
J

Joe

Thanks
-----Original Message-----


Bob

Try this:

Private Sub txtUnitsInStock_KeyDown(KeyCode As Integer, Shift As Integer)
If Not IsNumeric(Chr(KeyCode)) _
And (KeyCode <> 9) And (KeyCode < 96 And KeyCode > 105) _
Then KeyCode = 0
End Sub

--

Jon

www.applecore99.com - Access Tips and Tricks

.
 

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