Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NewLine in Textbox

Status
Not open for further replies.

kklaus

Technical User
Dec 8, 2004
36
US
I have a line of code that displays the selections the user makes in a combobox to a textbox. It separates each selection with a comma.

Here's the code:
Code:
ActiveDocument.FormFields("Text1").Result = temp & ", " & ComboBox1.Value

The result will display as:
Difference in Conditions, Flood and Earthquake Only, Flood Only

I would like to have a new line instead of the comma so the result would look like this:

Difference in Conditions
Flood and Earthquake Only
Flood Only

So I tried this code:
Code:
ActiveDocument.FormFields("Text1").Result = temp & vbNewLine & ComboBox1.Value

It works except it's putting a square shape in front of the last item in the list.

Any suggestions?

Thanks!
 
I have one more question to go along with this...

The text the users to select seems to be too long to fit inside a Text Form Field as I'm getting "String too long" error.

So how can I print/display my results to just a Text Box (that I find under the Insert menu)? It looks like I can fit more data in this kind of TextBox. However, I don't see a name associated with it like TextBox1 to reference in the code.

Thanks!
 
Ok. I got the NewLine to work now by changing vbNewLine to vbCr. Also, I resolved the String Too Long problem by doing this:
Code:
If temp = "" Then
    ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Text = ComboBox1.Value
Else
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Text = temp & vbCr & ComboBox1.Value
End If

Now the only question I have remaining is can I print this text to a Text Box that I would find under the Insert menu? I don't see a name associated with it like TextBox1 to reference in the code.

Thanks!
 
Instead of adding a textbox from the Insert menu, make the
Control Toolbox toolbar visible and use the TextBox control from that. You can right-click and select Properties to see/change the Name property which can then be used by your code to manipulate this.


Hope this helps,
Mike
 
Cool!

That's working, but how do I make the size of the textbox grow along with size of the text that is added to it?

Thanks!
 
I did that but I must have some other setting that is messing it up because the result looks like this:

D
i
f
f
e
r

etc...

It keeps setting the width to 18.75 and growing the height as large as it needs to for the amount of data.
 
You are great!!

Thanks for not giving up on me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top