PDA

View Full Version : Solved: Validating a textbox



SeanJ
05-19-2008, 09:51 AM
Is there a way to validate a testbox instead of using the following code.

Private Sub txtFlight_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Shift = 2 Then
If KeyCode = 86 Then KeyCode = 0
End If
End Sub
Private Sub txtFlight_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57
Case 65 To 90
Case 97 To 122

Case Else
KeyAscii = 0
End Select
End Sub

malik641
05-19-2008, 08:45 PM
Yes, yes you can. Thanks to MVIDAS :)

Private Sub txtFlight_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case True
Case Chr(KeyAscii) Like "[a-zA-Z0-9]"
Case Else: KeyAscii = 0
End Select
End Sub

Enjoy!