![]() |
exact number of characters in textbox
The program I am developing requires employees to enter information about
customer numbers. These customer numbers are always 11 digits long. I know how to limit the textbox to 11 characters but how do I check to see if all 11 characters were entered? |
exact number of characters in textbox
in the appropriate event for the textbox, use the len function
if len(me.Textbox1.Text) < 11 then There are two kinds of text boxes and textboxes can be located on worksheets, userforms, dialogsheets, and a more specific answer would require more specific knowledge although you will probably get some guesses. -- Regards, Tom Ogilvy "JNW" wrote in message ... The program I am developing requires employees to enter information about customer numbers. These customer numbers are always 11 digits long. I know how to limit the textbox to 11 characters but how do I check to see if all 11 characters were entered? |
exact number of characters in textbox
If Len(Textbox1.Text) < 11 Then
MsgBox "Too few digits" End If -- HTH RP (remove nothere from the email address if mailing direct) "JNW" wrote in message ... The program I am developing requires employees to enter information about customer numbers. These customer numbers are always 11 digits long. I know how to limit the textbox to 11 characters but how do I check to see if all 11 characters were entered? |
exact number of characters in textbox
Thank you Tom.
I did forget to include that this is on a userform. Will what you put below still work? Thank again "Tom Ogilvy" wrote: in the appropriate event for the textbox, use the len function if len(me.Textbox1.Text) < 11 then There are two kinds of text boxes and textboxes can be located on worksheets, userforms, dialogsheets, and a more specific answer would require more specific knowledge although you will probably get some guesses. -- Regards, Tom Ogilvy "JNW" wrote in message ... The program I am developing requires employees to enter information about customer numbers. These customer numbers are always 11 digits long. I know how to limit the textbox to 11 characters but how do I check to see if all 11 characters were entered? |
exact number of characters in textbox
Hi,
In this case you can use the Exit event for the textbox. If you use this code it should work: Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) Dim intPos As Integer If Len(TextBox1.Text) < 11 Then MsgBox "PLEASE ENTER 11 DIGTIS", vbExclamation, "Retry" Cancel = True Else For intPos = 1 To 11 If Not IsNumeric(Mid(TextBox1.Text, intPos, 1)) Then MsgBox "Please use numbers only", vbExclamation, "Retry" Cancel = True End If Next End If End Sub your user smust fill the textbox with 11 digits. As a bonus I have added a check on numbers opnly. HTH, Wouter |
exact number of characters in textbox
Hi,
Some extra info: You might need to change IsNumeric(Mid(TextBox1.Text, intPos, 1)) into IsNumeric(Mid(TextBox1.Text; intPos; 1)) where de , in changed into ; this depents on regional setting. Wouter |
All times are GMT +1. The time now is 11:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com