Textbox in red if to many characters and spaces in it

Wilder1626
Wilder1626 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Older than dirt
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
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
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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
Perfect thanks

It working great:

If Len(Text1.Text) > 500 Then
    Text1.BackColor = vbRed
    MsgBox "You are over: " & Len(Text1.Text) - "500"
End If
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You're welcome and I'm glad I was able to help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial