Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default 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?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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?



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
look for the exact number sctroy Excel Discussion (Misc queries) 1 September 25th 05 09:49 PM
Max numbers of characters in userform textbox and cell N E Body Excel Programming 4 June 27th 05 06:25 PM
UserForm; Textbox; Multiline; NonPrintable Characters sa3214[_2_] Excel Programming 3 November 3rd 04 03:46 PM
copy cell contents to a textbox 255 characters mcadle Excel Programming 7 September 7th 04 07:39 AM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


All times are GMT +1. The time now is 01:46 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"