+ Reply to Thread
Results 1 to 5 of 5

measure the length of text in 10 boxes consecutivly.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    measure the length of text in 10 boxes consecutivly.

    Hi all,

    I am trying to use a For loop to measure the lenght of text in 10 text boxes on a user form so I can run a check but can't think of a way to do it.

    This is the best I have so far...

    For Count = 1 To 10
        TextField = "Me.txtText" & Count
        TextLength = TextField.Length
        If TextLength > 50 Then
            If Error = "" Then
                Error = "Text field " & Count
            Else
                Error = Error & vbCrLf & "Text field " & Count
            End If
        End If
    Next
    Any help greatly appriciated.
    Last edited by duckboy1981; 02-16-2009 at 06:49 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: measure the length of text in 10 boxes consecutivly.

    What are the names of the textboxes?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: measure the length of text in 10 boxes consecutivly.

    txtText1 ... txtText10 - Very imanitive, dont you think!!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: measure the length of text in 10 boxes consecutivly.

    Maybe ...
        Dim i As Long
        
        For i = 1 To 10
            With Me.Controls("txtText" & i)
                If Len(.Value) > 50 Then
                    MsgBox .Name & " has too much text"
                    Cancel = True
                    .SetFocus
                    Exit Sub
                End If
            End With
        Next i

  5. #5
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: measure the length of text in 10 boxes consecutivly.

    Sorted, that works a treat. Thanks for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1