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
 

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

Back
Top