MS Access - Insert Text at cursor with SelText (1 Viewer)

ironfelix717

Registered User.
Local time
Today, 12:32
Joined
Sep 20, 2019
Messages
193
Hi,

The preferred method of inserting text at a cursor position in a textbox
appears to be setting the Textbox.SelText property.... This doesn't work for me
under any circumstances (RTF or Plain format). It simply erases the entire text box.

See attached.

Thanks for any help.
Regards
 

Attachments

  • InsertText.accdb
    404 KB · Views: 89

theDBguy

I’m here to help
Staff member
Local time
Today, 09:32
Joined
Oct 29, 2018
Messages
21,358
Hi. Just curious, have you tried SelStart instead?
 

vba_php

Forum Troll
Local time
Today, 11:32
Joined
Oct 6, 2019
Messages
2,884
if you can't fix it on ur own, this is dbGuy's solution....
 

Attachments

  • InsertText - fix.accdb
    768 KB · Views: 82

ironfelix717

Registered User.
Local time
Today, 12:32
Joined
Sep 20, 2019
Messages
193
Hi all,

The solution provided doesn't meet requirements because it does not insert text at the cursor position.

I've solved this in the attached example. The confusion was in the fact that the value of .SelStart was returning 0 unconditionally. Reason being, the cmdbutton gets focus and re-sets the property value. Storing this in a module var during the On_Click Event of the Textbox is the only solution to retain cursor position.

Thanks for the help!
Regards,
 

Attachments

  • InsertText - fix v2.accdb
    420 KB · Views: 132

theDBguy

I’m here to help
Staff member
Local time
Today, 09:32
Joined
Oct 29, 2018
Messages
21,358
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

ironfelix717

Registered User.
Local time
Today, 12:32
Joined
Sep 20, 2019
Messages
193
Hi. Glad to hear you got it sorted out. Good luck with your project.

Thanks DbGuy,

Update on this little issue:

This really isn't a good approach still for a multi-line rich textbox. Reason being,
if the user changes the cursor position vertically via arrows or enter or any other means OTHER than the mouse (paste, cut), the position is not captured in the module var. So i added a Textbox_Change event to capture the cursor pos, even still, the solution is lousy and unreliable.

Sad that something so trivial is so difficult. I will not be dedicating any more time to this feature.

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:32
Joined
Oct 29, 2018
Messages
21,358
Thanks DbGuy,

Update on this little issue:

This really isn't a good approach still for a multi-line rich textbox. Reason being,
if the user changes the cursor position vertically via arrows or enter or any other means OTHER than the mouse (paste, cut), the position is not captured in the module var. So i added a Textbox_Change event to capture the cursor pos, even still, the solution is lousy and unreliable.

Sad that something so trivial is so difficult. I will not be dedicating any more time to this feature.

Thanks
Hi. Unfortunately, everything has limitations. Sometimes, there's just nothing we can do about them. Sorry.
 

Users who are viewing this thread

Top Bottom