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.

Community
  • 1
  • 1
Bartek Malysz
  • 922
  • 5
  • 14
  • 37

2 Answers2

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!

Juri Noga
  • 4,363
  • 7
  • 38
  • 51
Fábio
  • 11
  • 2
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

Community
  • 1
  • 1
Vityata
  • 42,633
  • 8
  • 55
  • 100