User Form Help

R

robertguy

Dave,

I have gone with your code as I need to ensure the user clicks on th
ok button to display the data.

Having said that, can you please advise me how to tweak your code t
display the data in one text box (TextBox1) formatted with a vbcrlf i
between fields.

I have tried the code below i.e. :-

Me.TextBox1.Value = .Offset(myIndex, 1).Value + vbCrLf
.Offset(myIndex, 2) + vbCrLf + .Offset(myIndex, 3)

(and changed the + signs to &) which does not insert a carriage retur
but displays the three filed on one line with some sort of contro
character in between

Any guidance would be appreciated


Ro
 
D

Dave Peterson

+ is usually used to add numeric values
& is usually used to concatenate strings

VBA is forgiving enough to allow + to concatenate strings--but I wouldn't use
them. I think that someday, you'll be surprised by what happens--so why take a
chance?

When you're in the VBE designing your form, click on the textbox1.

Hit F4 (to show the properties).
Turn WordWrap to True
turn multiline to True
and maybe turn EnterKeybehavior to true.
Take a look at what that enterkeybehavior does in VBA's help (or just try it
when you're showing your form).

You can also do this in code.

Private Sub UserForm_Initialize()
With Me.TextBox1
.WordWrap = True
.MultiLine = True
.EnterKeyBehavior = True
End With
End Sub

I think that excelforum eats up the periods in the first character of a line
when you post, but there wasn't a dot in front of one of the .offset's in your
code:

Me.TextBox1.Value = .Offset(myIndex, 1).Value & vbNewLine _
& .Offset(myIndex, 2) & vbNewLine & .Offset(myIndex, 3)

I usually use vblf, but if you want OS independence (Win/Mac), vbNewLine is
better.
 
Top