Find Last instance of carriage return In a Memo Field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a form where the user usually pastes a glob of text into it a memo
field called "Comment". After he pastes the text, the cursor is obviously at
the end of the text. I would like the user to be able to click a button and
for the comment to be highlighted from the very end of the text to the first
instance of a carriage return going backwards. In other words, I want to
automatically select the very last line of the comment.



I was thinking that I could use seldown, but I would need to first find the
Last instance of Chr$(13). Or, can the instr function can be used in
reverse, meaning to search the string starting from the end of the line?

Thanks, in advance.
 
I was thinking that I could use seldown, but I would need to first find the
Last instance of Chr$(13). Or, can the instr function can be used in
reverse, meaning to search the string starting from the end of the line?

In A2002 and later, there is an InStrRev() function which does just this:

Me!txtboxname.SelStart = InStrRev(Me!txtboxname, vbCrLf)

John W. Vinson [MVP]
 
Back
Top