View Full Version : Block textbox for numbers or text.
pimentamarqu
10-29-2010, 06:10 AM
Hi,
Could someone tell me if is posible to block a textbox for numbers or text to prevent users to insert non desired character (text in this case) on a particular textbox.
Tks
Bob Phillips
10-29-2010, 06:14 AM
Select Case True
Case Chr(KeyAscii) >= "0" And Chr(KeyAscii) <= "9"
Case Else: KeyAscii = 0
End Select
pimentamarqu
11-03-2010, 06:11 AM
k, tks, but were should I insert this code?
Tinbendr
11-03-2010, 07:48 AM
Private Sub TextBox1_Change()
Select Case True
Case Chr(KeyAscii) >= "0" And Chr(KeyAscii) <= "9"
Case Else: KeyAscii = 0
End Select
End Sub
Bob Phillips
11-03-2010, 07:56 AM
No, use the Textbox KeyPress event.
pimentamarqu
11-10-2010, 04:25 AM
Tks,
to be able to use "." and numbers i used the following code:
Private Sub number1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case True
Case Chr(KeyAscii) >= "0" And Chr(KeyAscii) <= "9" Or Chr(KeyAscii) = "."
Case Else: KeyAscii = 0
End Select
End Sub
Bob Phillips
11-10-2010, 04:44 AM
Bit picky I know, but I would have used
Private Sub number1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case True
Case Chr(KeyAscii) >= "0" And Chr(KeyAscii) <= "9"
Case Chr(KeyAscii) = "."
Case Else: KeyAscii = 0
End Select
End Sub
Bob Phillips
11-10-2010, 04:45 AM
BTW, you might want to cater for backspace/delete as well.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.