Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Validate textbox entry
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Validate textbox entry
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 *** |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Validate textbox entry
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 *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Validate date entry in a text box. | Excel Discussion (Misc queries) | |||
validate duplicate entry in a column | Excel Discussion (Misc queries) | |||
Validate Email address entry | Excel Discussion (Misc queries) | |||
Validate Combobox entry | Excel Programming | |||
Validate Textbox entry | Excel Programming |