Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing Cursor in Text Box

Status
Not open for further replies.

scriverb

Programmer
May 17, 2002
4,485
US
I have a popup comments form that I prefill with variable information depending upon the sitution with my main form. In the OnLoad of the form I have the following code:

Me![Comments].SetFocus
Me![Comments] = vPopupComments
Me![Comments].SelLength = 0
Me![Comments].SelStart = Len(Me![Comments]) + 1


The number of prefilled lines will vary depending upon the number of clients in the case. So the following is an example of the data being prefilled:

Case#: 111111
Larry-
Bob-
Andy-

The user will fill in behind the names additional information as necessary. With the above code the cursor is placed at the end behind the last hyphen. Problem is the text box is set for scrolling vertical and only the line showing Andy- is visible. I want the entire text string to be visibile with the cursor at the end.

I am looking for something like a scrollup command. Can't seem to find it. Any ideas? Bob Scriver
 
I've managed to solve this problem by dynamically resizing the text box on got focus and on lost focus:

Private Sub Comments_GotFocus()
Dim i As Integer
For i = 1 To 100
Comments.Height = Comments.Height + i
Next
Comments.SelStart = Len(Nz(Comments, ""))
End Sub

Private Sub Comments_LostFocus()
Dim i As Integer
For i = 1 To 100
Comments.Height = Comments.Height - i
Next
End Sub

The For...Next loops are just for visual impression [smile]

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
I found the answer. I am posting for others to benefit:

On Open Event Procedure:
SendKeys "^{Home}"
SendKeys "^{End}"

This does the trick. It forces the entire string of text into the text control and places the cursor at the end.

Bob Scriver Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top