Textbox in red if to many characters and spaces in it

Hello all

I would like to know how i can validate the number of characters and spaces or used in the text1 when the bellow macro is over, so that if there is more then 500 characters and spaces all combined , it will put the textbox in red.

Thanks again for your help.


Dim s As String
Dim i As Long, j As Long, n As Long
For n = 1 To MSHFlexGrid1.Rows - 1
   If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
      If Len(s) > 0 Then
         s = s + ","
      End If
      s = s + "'" + MSHFlexGrid1.TextMatrix(n, 1) + "'"
   End If
Next



'CUST_PO in
If Option1.value = True Then

Text1 = "CUST_PO in " & "(" + s + ")"

End If

'ID in
If Option2.value = True Then

Text1 = "ID in " & "(" + s + ")"

End If

Open in new window

LVL 11
Wilder1626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
If Len(Text1.Text) > 500 Then
    Text1.ForeColor = vbRed
End If

Open in new window



-----------------------------------------------------------------------------------------------------------------------------------
My Articles:
Using the VB6 DebuggerAutomatic Insertion of Procedure Names
A Textbox ActiveX Control That Limits Input to NumbersSpell Check a Textbox
Improved Formatting Tags

Marty - MVP 2009, 2010, 2011
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Or Text1.BackColor = vbRed



-----------------------------------------------------------------------------------------------------------------------------------
My Articles:
Using the VB6 DebuggerAutomatic Insertion of Procedure Names
A Textbox ActiveX Control That Limits Input to NumbersSpell Check a Textbox
Improved Formatting Tags

Marty - MVP 2009, 2010, 2011
0
Wilder1626Author Commented:
Perfect thanks

It working great:

If Len(Text1.Text) > 500 Then
    Text1.BackColor = vbRed
    MsgBox "You are over: " & Len(Text1.Text) - "500"
End If
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.