I’m using Excel 2002
How can I determine in code whether a textbox on a form contains more than one line of text?
I have a form with a number of textboxes. Each textbox is 13 points high and therefore displays the first line of text for the field. If I click in the textbox its contents are displayed below in a larger textbox where I can view the entire entry and edit it.
I want the text in the smaller textboxes to change color if they are not displaying all the available text (ie if they have more than one line of text).
I’m currently doing this by searching for Chr(10) as below:
Private Sub UserForm_Initialize()
For Each MyControl In UserForm1.Controls
If Left(MyControl.Name, 4) = "Text" Then ‘If this control is a textbox
ColorLongOnes (MyControl.Name) ‘change the text color if it’s a long entry
End If
Next MyControl
…..
Private Sub ColorLongOnes(ThisTextBox)
If InStr(Controls(ThisTextBox).Text, Chr(10)) Then ‘If the text contains a carriage return
Controls(ThisTextBox).ForeColor = &HFF& ‘ Make the text red
End If
End Sub
This works fine most of the time however there are some long entries in the database for which this won’t work. (i.e – where the entry is just one long paragraph)
I thought about using
If Len(Textbox.Text) > X Then
but I don’t want to use a standard width font in the textboxes (where all the letters are the same width) so there’s no way to determine what X should be.
Can anyone help? I’ve searched the forum to no avail
How can I determine in code whether a textbox on a form contains more than one line of text?
I have a form with a number of textboxes. Each textbox is 13 points high and therefore displays the first line of text for the field. If I click in the textbox its contents are displayed below in a larger textbox where I can view the entire entry and edit it.
I want the text in the smaller textboxes to change color if they are not displaying all the available text (ie if they have more than one line of text).
I’m currently doing this by searching for Chr(10) as below:
Private Sub UserForm_Initialize()
For Each MyControl In UserForm1.Controls
If Left(MyControl.Name, 4) = "Text" Then ‘If this control is a textbox
ColorLongOnes (MyControl.Name) ‘change the text color if it’s a long entry
End If
Next MyControl
…..
Private Sub ColorLongOnes(ThisTextBox)
If InStr(Controls(ThisTextBox).Text, Chr(10)) Then ‘If the text contains a carriage return
Controls(ThisTextBox).ForeColor = &HFF& ‘ Make the text red
End If
End Sub
This works fine most of the time however there are some long entries in the database for which this won’t work. (i.e – where the entry is just one long paragraph)
I thought about using
If Len(Textbox.Text) > X Then
but I don’t want to use a standard width font in the textboxes (where all the letters are the same width) so there’s no way to determine what X should be.
Can anyone help? I’ve searched the forum to no avail