Numbers in a text property.

  • Thread starter Thread starter Bob
  • Start date Start date
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
 
"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.
 
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

.
 
Thanks
But, the Tab button, the numbers on the right side on the
keyboard doesn't work. Can you fix that?
Thanks
 
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" 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
 
"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.
 
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
 
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

.
 
Back
Top