Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Validating number of characters in textbox


Hi. I want to validate the data entry on a textbox so that a message box
appears if the user inputs a reference less than 7 digits long. (part of
a form which adds a new record to the sheet) I've set the textbox to
maxlength of 7 but can't get the code right. Please could someone
assist. Here is what I have so far which doesn't work:

If not TextBox1.MaxLength Then
MsgBox "The entry has to be 7 digits long"
TextBox1.SetFocus
Exit Sub
End If

Thank you.


--
Blondegirl
------------------------------------------------------------------------
Blondegirl's Profile: http://www.excelforum.com/member.php...o&userid=29615
View this thread: http://www.excelforum.com/showthread...hreadid=540634

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Validating number of characters in textbox


Try

If not len(TextBox1) = 7 Then
MsgBox "The entry has to be 7 digits long"
TextBox1.SetFocus
Exit Sub
End If


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=540634

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Validating number of characters in textbox

Do it on the EXIT event of textbox1 as follows

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox1) < 7 Then
MsgBox "Text must be 7 characters long"
Cancel = True
End If
End Sub

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
validating input of textbox before publishing eyesonly1965 Excel Programming 4 May 7th 06 03:18 PM
exact number of characters in textbox JNW Excel Programming 5 October 21st 05 10:51 AM
validating input in textbox Jean-Pierre D via OfficeKB.com Excel Programming 1 August 15th 05 08:37 PM
Excel VBA - Cursor disappears when validating content of a TextBox lonewolfbr Excel Programming 0 September 16th 04 09:49 PM
Validating Entry into Textbox Brad[_11_] Excel Programming 1 December 4th 03 02:58 PM


All times are GMT +1. The time now is 09:23 AM.

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

About Us

"It's about Microsoft Excel"