|
-
Jul 17th, 2000, 07:10 PM
#1
Thread Starter
Hyperactive Member
Hi,
Below is the code that limits user's input to letters & digits only (in a TextBox). It works great, however I have 3 text boxes on my form & would like to check them all WITHOUT retyping the same rutine 3 times.
Can you guys let me know how to write all-purpose Sub/Function that will do the same thing for any text box (not just 'Text1'). Go Reusability!!!
As always Thanks for your help.
---------------------------------------------------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim strChar As String
' Accept the key if its a "control character" ...
If KeyAscii < 32 Then
Exit Sub
End If
strChar = Chr$(KeyAscii)
' Accept the key if it's numeric ...
If strChar >= "0" And strChar <= "9" Then
Exit Sub
End If
strChar = UCase$(strChar)
' Accept the key if it's alpha ...
If strChar >= "A" And strChar <= "Z" Then
Exit Sub
End If
' Otherwise, reject the key ...
KeyAscii = 0
End Sub
---------------------------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|