Use the KeyDown event. This is some code, I use to allow the users only
to enter numbers for a zipcode:
Private Sub ZipCode_KeyDown(ByVal KeyCode As _ MSForms.ReturnString,
ByVal Shift As String)
With Me.ZipCode
Select Case True
Case (KeyCode = 95 And KeyCode < 105)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub
Modify your's like so:
Private Sub TextBox1_KeyDown(ByVal KeyCode As _ MSForms.ReturnString,
ByVal Shift As String)
With Me.ZipCode
Select Case True
Case (KeyCode = 97 And KeyCode < 122)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case (KeyCode = 65 And KeyCode < 90)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub
I might have something wrong, modifying it to fit your needs. But it's
enough to get started.
*** Sent via Developersdex
http://www.developersdex.com ***