Place curser at end of line?

M

Macsmasher

Hi everybody,

Running Access07

I have a memo field that I will use as a journal. There is a cmd button
that I want to place the curser at the beginning of any existing text,
insert two lines, insert the UserName and date, then place the curser at the
end of that new line so
the User can begin typing. The below code works fine with the exception for
placing the curser at the end of the line. Since using SendKeys "{END}" is
never a good idea, I need either something to replace it, or a suggestion on
how to do this differently.

strUser = Forms![frmSwitchboard]![txtCurrentUser]
With Me.memAdminNote
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strUser & " " & Date & ": "
' replace SendKeys "{END}" with what???
End With

Thanks in advance for your input!

-Larry
Maximize Software, Inc.
 
K

Klatuu

You use the selstart property to position the cursor at any point in the
text. You are using ": " to terminate your current entry, so you would want
to position it right after that, so it would look like
<> blank line
<> blank line
Fred 07/23/2009: |
cursor here ---^
Here is all you need:

strUser = Forms![frmSwitchboard]![txtCurrentUser]
With Me.memAdminNote
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strUser & " " & Date & ": "
.SelStart = Instr(Me.memAdminNote, ": ")
End With
 
M

Macsmasher

Hi Dave,

Thank you for the response, but what you suggested placed the curser down in
the first line of existing text below the two inserted lines. However, the
following works great:

Dim strUser As String
Dim strDateStamp As String

strUser = Forms!frmSwitchboard!txtCurrentUser
strDateStamp = strUser & " " & Date & ": "

With Me.memComments
.Locked = False
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strDateStamp
.SelStart = Len(strDateStamp)
.SelLength = 0
End With


Klatuu said:
You use the selstart property to position the cursor at any point in the
text. You are using ": " to terminate your current entry, so you would want
to position it right after that, so it would look like
<> blank line
<> blank line
Fred 07/23/2009: |
cursor here ---^
Here is all you need:

strUser = Forms![frmSwitchboard]![txtCurrentUser]
With Me.memAdminNote
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strUser & " " & Date & ": "
.SelStart = Instr(Me.memAdminNote, ": ")
End With

--
Dave Hargis, Microsoft Access MVP


Macsmasher said:
Hi everybody,

Running Access07

I have a memo field that I will use as a journal. There is a cmd button
that I want to place the curser at the beginning of any existing text,
insert two lines, insert the UserName and date, then place the curser at the
end of that new line so
the User can begin typing. The below code works fine with the exception for
placing the curser at the end of the line. Since using SendKeys "{END}" is
never a good idea, I need either something to replace it, or a suggestion on
how to do this differently.

strUser = Forms![frmSwitchboard]![txtCurrentUser]
With Me.memAdminNote
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strUser & " " & Date & ": "
' replace SendKeys "{END}" with what???
End With

Thanks in advance for your input!

-Larry
Maximize Software, Inc.
 
K

Klatuu

hhhmmm, worked for me, but I like your idea better anyway.
--
Dave Hargis, Microsoft Access MVP


Macsmasher said:
Hi Dave,

Thank you for the response, but what you suggested placed the curser down in
the first line of existing text below the two inserted lines. However, the
following works great:

Dim strUser As String
Dim strDateStamp As String

strUser = Forms!frmSwitchboard!txtCurrentUser
strDateStamp = strUser & " " & Date & ": "

With Me.memComments
.Locked = False
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strDateStamp
.SelStart = Len(strDateStamp)
.SelLength = 0
End With


Klatuu said:
You use the selstart property to position the cursor at any point in the
text. You are using ": " to terminate your current entry, so you would want
to position it right after that, so it would look like
<> blank line
<> blank line
Fred 07/23/2009: |
cursor here ---^
Here is all you need:

strUser = Forms![frmSwitchboard]![txtCurrentUser]
With Me.memAdminNote
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strUser & " " & Date & ": "
.SelStart = Instr(Me.memAdminNote, ": ")
End With

--
Dave Hargis, Microsoft Access MVP


Macsmasher said:
Hi everybody,

Running Access07

I have a memo field that I will use as a journal. There is a cmd button
that I want to place the curser at the beginning of any existing text,
insert two lines, insert the UserName and date, then place the curser at the
end of that new line so
the User can begin typing. The below code works fine with the exception for
placing the curser at the end of the line. Since using SendKeys "{END}" is
never a good idea, I need either something to replace it, or a suggestion on
how to do this differently.

strUser = Forms![frmSwitchboard]![txtCurrentUser]
With Me.memAdminNote
.SetFocus
.SelStart = 0
.SelText = vbNewLine & vbNewLine
.SelText = strUser & " " & Date & ": "
' replace SendKeys "{END}" with what???
End With

Thanks in advance for your input!

-Larry
Maximize Software, Inc.
 
K

Klatuu

Good point, Linq. In this case; however, the OP is not wanting to select the
entire field, but at which point in the text to position the cursor. The
only use of the SelLength is to set it to 0 so the text from the beginning to
the cursor is not selected (highlighted)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top