I'll take up the reins for a couple of posts. First a question
I would like to click a button which would insert the "*" character at the cursor position of a field with long text.
rather than clicking a button, why not just insert the * character. You can include code on the keypress event to ignore any other character.
But to do it your way, this is where some examples would come in handy as this suggestion may or may not work - all depends if there are duplicates
1. in your form module create a common variable
Code:
dim sstart as integer
in your richtext control lost focus event put
Code:
sstart = Text0.SelStart
in your button click event put
Code:
Dim ptxt As String
Dim stxt As String
ptxt = PlainText(Text0)
stxt = Mid(ptxt, sstart+1, 5) 'adjust the 5 to suit - the expectation is that the 5 (plaintext) characters following the cursor position is unique. If the cursor position is within 5 chars of the end, only the remaining chars will be used
'edited to include +1
myRTControl = Replace(myRTControl, stxt, "*" & stxt, , 1) ' the 1 tries to mitigate duplicates
Edit: just done a bit more testing - if there is formatting code within the following 5 chars of the richtext string, the code will fail because the replace won't insert the "*" as an exact match on the plaintext string is not found
Edit#2: selstart is an integer, so a maximum value of 32767. Long text can be considerably longer than that so this code will also fail if this is the case