LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Force Scroll Bar Down on TextBox Control

The following sub does not make sense to me. lLine is saved to the current
CurLine value and then you are setting Curline to the same value so the
cursor should not move.

CurLine is the current line where the cursor is positioned.

Private Sub SetScrollBar()
UserForm1.TextBox1.SetFocus
lLine = UserForm1.TextBox1.CurLine 'Public Variable
UserForm1.TextBox1.CurLine = lLine
UserForm1.TextBox1.SetFocus
End Sub

You need to save CurLine to lLine variable immediately after entering the
last of the data in the TextBox1 while the cursor is still on the last line.
I have not been able to do that reliably because the user might move up
through the textbox to edit an error and then move to another control from
there.

From my testing it appears that you can only set the cursor to the specified
CurLine if the TextBox has focus. Therefore must SetFocus to the TextBox
first. Having said that, it also appears that it only works if done in the
last line of code executed before the End Sub like the following example. Any
code after the line of code to set the cursor to Curline will nullify the
CurLine setting:-

Sub test()
UserForm1.Show vbModeless
UserForm1.TextBox1.SetFocus
UserForm1.TextBox1.CurLine = 6 'Can use a variable in lieu of 6
End Sub

Next I found that using the above code to set the cursor to the last line
then it would only work if I used a value 1 less then should be required.
Example if 8 lines then should be 7 because of Zero to 7 line count. However,
I had to set it to 6 or I got an error. Also 6 actually set it to the last
line which should be 7.

Now if I run code from a Command button after the form is opened then I had
to set it 7 to get the last line like the following:-

Private Sub CommandButton1_Click()
Me.TextBox1.SetFocus
Me.TextBox1.CurLine = 7
End Sub

The 6 or 7 just does not make sense to me.

My next test was to use SendKeys to send a Ctrl/End when the control gets
focus. As much as I dislike the use of SendKeys it appears to be more
reliable and I dont think that sending Ctrl/End after the TextBox has focus
will ever cause a problem. (Note: Must still SetFocus to the TextBox first.)

Sub test()
UserForm1.Show vbModeless
UserForm1.TextBox1.SetFocus
Application.SendKeys ("^{END}")
End Sub

The above code also worked well from a CommandButton as per the following:-

Private Sub CommandButton1_Click()
Me.TextBox1.SetFocus
Application.SendKeys ("^{END}")
End Sub

Just a little added extra. I also tried to use both the CurLine method and
Sendkeys method with the TextBox Enter Event. It does not work when you use
the mouse to click on the TextBox. In Help it says that Enter Event code
actually takes place before the real enter takes place and I am sure that
this is the reason for this. It does not actually have focus until the Enter
Event code is finished running.

Hope this all helps. It was an interesting experiment for myself but in the
end I didnt progress all that far.

--
Regards,

OssieMac


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Force to update textbox value to cell Ueli Werner Excel Programming 1 March 20th 09 02:30 PM
How to force smooth scroll in excel? The-trooper Excel Discussion (Misc queries) 1 March 4th 09 02:43 PM
How to force selection of all current text in textbox control onentry? Chrisso Excel Programming 2 November 25th 07 09:55 PM
How to move cursor from one textbox control to another textbox con Tom Ogilvy Excel Programming 1 September 16th 04 03:42 PM
How to move cursor from one textbox control to another textbox con KMoore007 Excel Programming 0 September 16th 04 02:47 PM


All times are GMT +1. The time now is 04:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"