1

I have a workbook with an userform that captures user input into string and single variables and I want to display a text consisting those variables into a text box on the same userform using new line and tab.

Example:

Dim dog as String 'rex
Dim years as Single '5
Dim owner As String 'Joe
Dim address as String '123 Sample Street
Dim value as Single '300.00

I would like to have a textbox on my form, that would display:

The dog's name is rex. He is 5 years old.

Owner:                    Joe
Address:                 123 Sample Street

Treatment value:   300.00

I used

textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine & "Owner: " & owner & vbNewLine & "Address: " & address & vbNewLine & vbNewLine & "Treatment value: " & value

But after some time i will not be able to add another character to this line and I have plenty more variables mixed with text to come.

Can you suggest how this can be done?


Update: Resolved

Many thanks for your help.

0

2 Answers 2

1

Try

textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine

textbox.value = textbox.value & "Owner: " & owner & vbNewLine

textbox.value = textbox.value & "Treatment value: " & value & vbNewLine 

Continue with other fields!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Fabio, Works well, but Vityata's methods works better for me.
0

Try like this:

textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine & _
"Owner: " & owner & vbNewLine & _
"Address: " & address & vbNewLine & vbNewLine _
& "Treatment value: " & value

The " _" signs help you break the code into more lines. Note, that we have 2 signs - space and underscore there.

A small info - it is possibly good to consider passing the text as a .Text and not as .Value. Here is something good to read - Distinction between using .text and .value in VBA Access

3 Comments

the PO was not formatted, I think he want to have VBTab in between
Could be. But I think he is going to the end of the line of the VBEditor.
Thank you mate. Also + for the tip on .text vs .value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.