userform textbox scrollbar behaviour

ashleywanless

Board Regular
Joined
Aug 4, 2009
Messages
158
hi,

I have built a userform with several textboxes which show data, the data is never amended or input, its read from a sheet. I have set the textbox scrollbars property to 2 (fmscrollbarsvertical).

When my form loads the scrollbars do not appear until a user clicks on the textbox, i would like them to all appear constantly, is this possible?

Also when i do click in a textbox with a scrollbar this then jumps to the bottom of the data in that textbox, is it possible for this to jump to the start?

thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Put this in the UserForm_Initialize procedure for each textbox.
Code:
    TextBox1.SetFocus
    TextBox1.SelStart = 0
    TextBox2.SetFocus
    TextBox2.SelStart = 0
    TextBox3.SetFocus
    TextBox3.SelStart = 0
 
Upvote 0
Putting this in the userform's code module worked for me.
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With TextBox1
        .SelStart = 0
        .SelLength = 0
    End With
End Sub

Private Sub UserForm_Initialize()
    With TextBox1
        .ScrollBars = fmScrollBarsVertical
        .EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
    End With
End Sub
 
Upvote 0
Thanks for the code, but the cursor appears at the end of the text, is anyway that the user would see the text from the first line?

Putting this in the userform's code module worked for me.
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With TextBox1
        .SelStart = 0
        .SelLength = 0
    End With
End Sub

Private Sub UserForm_Initialize()
    With TextBox1
        .ScrollBars = fmScrollBarsVertical
        .EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
    End With
End Sub
 
Upvote 0
Thanks for the code, but the cursor appears at the end of the text, is anyway that the user would see the text from the first line?


Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] TextBox1_Exit([color=darkblue]ByVal[/color] Cancel [color=darkblue]As[/color] MSForms.ReturnBoolean)
    [color=darkblue]With[/color] TextBox1
        .SelStart = 0
        .SelLength = 0
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
    
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] UserForm_Initialize()
    [color=darkblue]With[/color] TextBox1
        .ScrollBars = fmScrollBarsVertical
        .EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
[B]        .SelStart = 0
        .SelLength = 0[/B]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Hi everyone,

I am facing a similar problem: I am printing the results of my userform calculations into a textbox with the last printed line being visually first. I want the textbox to constantly be scrolled to top, unless the user enters the textbox and scrolls lower.

It works when exiting the TextBox (
TextBox1.Exit() has SelStart = 0) , but facing problems when entering.

By putting:


Code:
 [COLOR=darkblue]With[/COLOR] TextBox1
        .ScrollBars = fmScrollBarsVertical
        .EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
[B]        .SelStart = 0
        .SelLength = 0[/B]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]

Inside UserForm Initialize - nothing happens. By putting it in Sub TextBox1.Enter() then the scroll remains on top, but when entering the textbox, the scrollbar will not appear and the content below the bottom line of the box cannot be seen.

Any advice?


Regards,
 
Upvote 0
If the user isn't expected to enter data into the text box, you could set the .SelStart in the text box Change event.
Otherwise, you could specify the .SelStart immediately after every line that writes to the box.
 
Upvote 0
If SelStart = 0 is put in TextBox1.Change() event, the outcome is the same as by putting it in the TextBox1.Enter() - everything is fine until the text gets longer than the textbox. When it happens, then entering the textbox yields no visible vertical scrollbar and no possible way to see the content that has gone below the bottom line.

What am I missing? If SelStart just sets the starting point of the selection/text, then why doesnt a vertical scrollbar appear? The text is there, for sure, since it gradually builds up in the textbox.
 
Upvote 0
The basic issue is that Microsoft designed Textboxes thinking the user would see the whole entry while typing.
Excel is a spreadsheet, not a data base, not a word processor.

Make the text boxes an appropriate size for the anticipated entries.
Or you could set the .AutoSize to True.
 
Upvote 0
The basic issue is that Microsoft designed Textboxes thinking the user would see the whole entry while typing.
Excel is a spreadsheet, not a data base, not a word processor.

Make the text boxes an appropriate size for the anticipated entries.
Or you could set the .AutoSize to True.

That may be true, but I've found that the following fixes the problem for me. I place this code in the procedure that loads the textbox value (I use both horizontal and vertical scrollbars, but only vertical also works):

Code:
With txtQuery
        .ScrollBars = fmScrollBarsBoth
        .EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
        ' Set the value
        .Value = q
        ' Force display of scrollbars
        .SetFocus
        .SelText = q
        ' Reset selection
        .SelStart = 0
        .SelLength = 0
        .SelText = ""
End With
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top