PC Review


Reply
Thread Tools Rate Thread

Checking number of characters in a TextBox

 
 
Patrick C. Simonds
Guest
Posts: n/a
 
      24th Oct 2008
The code below check to ensure there is data in TextBox2 but I need to add
another If Statement to ensure that the number of characters in TextBox2
equals 3 characters.

If TextBox2.Text = "" Then 'Initials
MsgBox "Sorry but you must enter your initials"
MultiPage1.Value = 0
GoTo MissingData
End If

 
Reply With Quote
 
 
 
 
Patrick C. Simonds
Guest
Posts: n/a
 
      24th Oct 2008
Never mind

Figured it out.

If TextBox2.TextLength <> 3 Then
MsgBox "Sorry but you must enter a 3 character initials"
MultiPage1.Value = 0
GoTo MissingData
End If



"Patrick C. Simonds" <(E-Mail Removed)> wrote in message
news:e4zaa$(E-Mail Removed)...
> The code below check to ensure there is data in TextBox2 but I need to add
> another If Statement to ensure that the number of characters in TextBox2
> equals 3 characters.
>
> If TextBox2.Text = "" Then 'Initials
> MsgBox "Sorry but you must enter your initials"
> MultiPage1.Value = 0
> GoTo MissingData
> End If


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      24th Oct 2008
Try this...

If Not TextBox2.Text Like "???" Then
MsgBox "Sorry but you must enter your initials"
MultiPage1.Value = 0
GoTo MissingData
End If

You didn't show the rest of your code, so its hard to offer you an
alternative, but, personally, I would rather not see GoTo being used in code
like this except as part of an On Error GoTo statement.

--
Rick (MVP - Excel)


"Patrick C. Simonds" <(E-Mail Removed)> wrote in message
news:e4zaa$(E-Mail Removed)...
> The code below check to ensure there is data in TextBox2 but I need to add
> another If Statement to ensure that the number of characters in TextBox2
> equals 3 characters.
>
> If TextBox2.Text = "" Then 'Initials
> MsgBox "Sorry but you must enter your initials"
> MultiPage1.Value = 0
> GoTo MissingData
> End If


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      24th Oct 2008
This is a little nit-pickish but not everyone has three initials and some
people have more than three. Also some people add, jr. or sr. as part of
their initials. So you might have to use a message box to set the rules for
entering the initials.

"Patrick C. Simonds" wrote:

> Never mind
>
> Figured it out.
>
> If TextBox2.TextLength <> 3 Then
> MsgBox "Sorry but you must enter a 3 character initials"
> MultiPage1.Value = 0
> GoTo MissingData
> End If
>
>
>
> "Patrick C. Simonds" <(E-Mail Removed)> wrote in message
> news:e4zaa$(E-Mail Removed)...
> > The code below check to ensure there is data in TextBox2 but I need to add
> > another If Statement to ensure that the number of characters in TextBox2
> > equals 3 characters.
> >
> > If TextBox2.Text = "" Then 'Initials
> > MsgBox "Sorry but you must enter your initials"
> > MultiPage1.Value = 0
> > GoTo MissingData
> > End If

>
>

 
Reply With Quote
 
Patrick C. Simonds
Guest
Posts: n/a
 
      24th Oct 2008
Thanks for your reply.

A 3 letter initial was a requirement imposed on me by the person requesting
the worksheet that I am developing. I did consider the fact that not
everyone has a middle name and amended my message to what you see below.


If TextBox2.TextLength <> 3 Then
MsgBox "Sorry but your initials must be 3 characters. Enter a ? for your
middle initial if you do not have one"
MultiPage1.Value = 0
GoTo MissingData
End If

"JLGWhiz" <(E-Mail Removed)> wrote in message
news:279D145F-13FC-40A9-89DD-(E-Mail Removed)...
> This is a little nit-pickish but not everyone has three initials and some
> people have more than three. Also some people add, jr. or sr. as part of
> their initials. So you might have to use a message box to set the rules
> for
> entering the initials.
>
> "Patrick C. Simonds" wrote:
>
>> Never mind
>>
>> Figured it out.
>>
>> If TextBox2.TextLength <> 3 Then
>> MsgBox "Sorry but you must enter a 3 character initials"
>> MultiPage1.Value = 0
>> GoTo MissingData
>> End If
>>
>>
>>
>> "Patrick C. Simonds" <(E-Mail Removed)> wrote in message
>> news:e4zaa$(E-Mail Removed)...
>> > The code below check to ensure there is data in TextBox2 but I need to
>> > add
>> > another If Statement to ensure that the number of characters in
>> > TextBox2
>> > equals 3 characters.
>> >
>> > If TextBox2.Text = "" Then 'Initials
>> > MsgBox "Sorry but you must enter your initials"
>> > MultiPage1.Value = 0
>> > GoTo MissingData
>> > End If

>>
>>


 
Reply With Quote
 
Patrick C. Simonds
Guest
Posts: n/a
 
      24th Oct 2008
Thanks for your reply.

This code is part of a series of tests to ensure that all mandatory
TextBoxes are filled in. I would be happy to submit all of the code for you
but I was trying to keep the message down to a reasonable length.


"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:O$(E-Mail Removed)...
> Try this...
>
> If Not TextBox2.Text Like "???" Then
> MsgBox "Sorry but you must enter your initials"
> MultiPage1.Value = 0
> GoTo MissingData
> End If
>
> You didn't show the rest of your code, so its hard to offer you an
> alternative, but, personally, I would rather not see GoTo being used in
> code like this except as part of an On Error GoTo statement.
>
> --
> Rick (MVP - Excel)
>
>
> "Patrick C. Simonds" <(E-Mail Removed)> wrote in message
> news:e4zaa$(E-Mail Removed)...
>> The code below check to ensure there is data in TextBox2 but I need to
>> add another If Statement to ensure that the number of characters in
>> TextBox2 equals 3 characters.
>>
>> If TextBox2.Text = "" Then 'Initials
>> MsgBox "Sorry but you must enter your initials"
>> MultiPage1.Value = 0
>> GoTo MissingData
>> End If

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining max number of characters in a TextBox =?Utf-8?B?VXNtYWFr?= Microsoft VB .NET 4 7th Sep 2006 05:21 AM
Textbox: Number of Characters Bill Microsoft Excel Programming 1 2nd Jul 2006 10:12 PM
Validating number of characters in textbox Blondegirl Microsoft Excel Programming 2 10th May 2006 01:57 PM
exact number of characters in textbox =?Utf-8?B?Sk5X?= Microsoft Excel Programming 5 21st Oct 2005 10:51 AM
Get the number of visible characters in textbox Nacho Nachev Microsoft Dot NET Framework Forms 2 1st Oct 2004 03:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 AM.