Inserting text within text

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have a bound field on a continuous form. Is there a way to insert some
text at the cursor location via code? How?

Thanks

Regards
 
Hi John

The beginning of the current selection in a textbox is given by the SelStart
property. The Length of the selection is SelLength. If no range is
selected then SelLength will be zero. In either case, SelStart gives the
cursor position. Note that SelStart is zero-based, so if it is 5, it means
*after* the 5th character.

So, to insert some text at the cursor, you could do something like this:

With txtMyTextBox
.Text = Left( .Text, .SelStart ) & strTextToInsert _
& Mid ( .Text, .SelStart+1)
' the following is optional
.SelStart = .SelStart + Len( strTextToInsert )
.SelLength = 0
End With
 
Back
Top