PDA

View Full Version : user form textbox issue



kavkazi
01-24-2011, 01:48 PM
Hi,

I'm creating a user form textbox to display a large message because msgbox has character limitation.

I created a user form, added a text box and changed the follwoing properties:
MultiLine = True
ScrollBars = 2 - fmScrollBarsVertical
Width = 600
WordWrap = True.

In the vba code of this form I have the following:

Private Sub TextBox1_Change()
TextBox1.Text = txt
End Sub

I have another sub which passes text to global variable txt and at the end shows the form.

Global txt As String
Sub text()
txt = Sheets("Sheet4").Cells(i, "B").Text & vbNewLine & _
Sheets("Sheet4").Cells(i, "C").Text & vbNewLine & _
Sheets("Sheet4").Cells(i, "D").Text & vbNewLine & _
Sheets("Sheet4").Cells(i, "E").Text & vbNewLine & _
Sheets("Sheet4").Cells(i, "F").Text & vbNewLine & _
Sheets("Sheet4").Cells(i, "H").Text & vbNewLine & vbNewLine
UserForm1.Show
End Sub

The problem is: The form shows up with the text box, but no text in it. When I click inside and type any key. The text shows up. Why does this happen? and how do i make the text show up right away on load?

Thanks

Aussiebear
01-24-2011, 02:20 PM
The form is loading but nothing actually triggers the textbox1_change event until you give it the focus.

Tinbendr
01-24-2011, 02:32 PM
Move the txt = Sheets("Sheet4").Cells(i, "B").Text & vbNewLine & _
Sheets("Sheet4").Cells(i, "C").Text & vbNewLine & _ ... to the Userform_Initialize event

David