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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

place cursor behind last text in memo field 2

Status
Not open for further replies.

rene1000

IS-IT--Management
Apr 9, 2002
89
NL
I have created a button which inputs the date in a memo field. Once this is done i want to put the focus on the memo field again and i would like the cursor to be placed behind the just inserted date.

this is what i have so far:

Screen.PreviousControl = description & vbCrLf & vbCrLf & Date & " : "
Screen.PreviousControl.SetFocus

this however place the cursor in the upmost left corner of the memo field. Anyone know how to achieve what i want ?
 
Use the SelStart property to position the cursor where you want it within the text in the field, but the Screen.PreviousControl object doesn't support this property. So you'll need to assign the previous control to a control variable (or textbox variable). For instance:

Code:
Dim ctl As Control
Set ctl = Screen.PreviousControl

ctl = Date
ctl.SetFocus
ctl.SelStart = Len(ctl)

Ken S.
 
Again a very helpfull post Ken. many thanks !
 
Hi rene1000,

I would avoid using Screen.PreviousControl for a situation like this. If the button is clicked while another field other than "MemoFieldName" has the Focus, problems will arise.

Dim ctlTextToSearch As Control, strDescription As String, intFind As Integer, strFind As String
strDescription = "Replace this with Text or a Control Name, rename MemoFieldName with your MemoFieldName"
Set ctlTextToSearch = Me!MemoFieldName
ctlTextToSearch.SetFocus
ctlTextToSearch.Text = strDescription & vbCrLf & vbCrLf & Date & " : "
With Me!MemoFieldName
strFind = Date
intFind = InStr(.Value, strFind)
.SetFocus
.SelStart = intFind - 1
.SelLength = Len(strFind)
End With

Bill
 
Hi Bill

You are right about that. Thanks for bringing that up

Rene
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top