I present a textbox where the user knows to enter only text (upper case,
lower case or a mixture) and/or numbers. Also no spaces.
I can use trim to remove spaces.....but how to check for just alphabetic
characters and numbers, please?
Regards.
I present a textbox where the user knows to enter only text (upper case,
lower case or a mixture) and/or numbers. Also no spaces.
I can use trim to remove spaces.....but how to check for just alphabetic
characters and numbers, please?
Regards.
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 ***
I actually started modifying it for your needs before I started the
post. So ignore my first piece of code, and only take a look at the
second part.
*** Sent via Developersdex http://www.developersdex.com ***
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks