Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate date entry in a text box. GoBow777 Excel Discussion (Misc queries) 0 July 30th 08 08:46 PM
validate duplicate entry in a column wangan Excel Discussion (Misc queries) 4 June 5th 07 01:38 PM
Validate Email address entry Rayasiom Excel Discussion (Misc queries) 2 May 31st 07 10:36 AM
Validate Combobox entry MBlake Excel Programming 5 May 4th 05 08:39 PM
Validate Textbox entry David Seebaran Excel Programming 3 April 18th 04 06:26 PM


All times are GMT +1. The time now is 05:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"