Referencing Selected Text (1 Viewer)

jatfill

Registered User.
Local time
Today, 06:27
Joined
Jun 4, 2001
Messages
150
Hi all,
I've searched on this to no result unfortunately.. but I am wondering if it is possible in Access/VBA to reference highlighted content within a text/memo box. I've tried several methods but nothing seems to work. This is Access 2002/XP.

So for example, if my message above had the word "possible" highlighted by a user, the a button click replaces the selected word with "impossible", retaining the other text around it... make sense?

I looked at the SelText property, which comes close... but if you reference this on a button the selected text gets wiped out when the textbox loses focus to the button. My first attempt at a workaround was to create a shortcut menu, but it doesn't respond to the module command.

I might be asking a bit much of my old friend Access at this point, I don't know... thanks in advance for any ideas!

[edit] OK I was able to get it to see the value of the selected text, but it won't change it to my replacement string, just thought I'd update...
 
Last edited:

bradcccs

Registered User.
Local time
Today, 20:27
Joined
Aug 9, 2001
Messages
461
Post you current code to avoid us rehashing what you already have achieved.
 

jatfill

Registered User.
Local time
Today, 06:27
Joined
Jun 4, 2001
Messages
150
Code:
Public Function UpdateSTxt(ByVal strContent As TextBox)
strContent.SelText = "impossible"
End Function

I added this in a new module and then call it from a shortcut menu command, available by right-clicking within the target textbox... so the menu command looks like

=UpdateSTxt(Forms!Form1!txtBoxName)


make sense?
 

WayneRyan

AWF VIP
Local time
Today, 11:27
Joined
Nov 19, 2002
Messages
7,122
jat,

The .SelText is just a value returned that equals
the highlighted text in your control. You can
not modify it.

What you can do is:

Code:
Me.YourControl = Mid(Me.YourControl, 1, Me.YourControl.SelStart - 1) & _
                 "Your New Text" & _
                 Mid(Me.YourControl, Me.YourControl.SelStart + Me.YourControl.SelLength + 1, Len(Me.YourControl))

Or something like that ...

Wayne
 

jatfill

Registered User.
Local time
Today, 06:27
Joined
Jun 4, 2001
Messages
150
I jus wanted to post back & let all know I was actually able to implement my original idea by using a custom shortcut menu on the textbox. My intent was to create a LOW-level HTML formatting tool for a calendar of events ASP page. so my final code went something like this (adding bold tags in this example):

Code:
Public Function WBold(ByVal strContent As TextBox)
strContent.SelText = "<b>" & strContent.SelText & "</b>"
End Function

so then I just added this to a custom menu command:

=WBold(Forms!frmWebFormat!txtcontent)

works like a charm... thanks again to everyone for their suggestions!
 

WayneRyan

AWF VIP
Local time
Today, 11:27
Joined
Nov 19, 2002
Messages
7,122
ON what does that have to do with your initial problem ...

Wayne
 

Users who are viewing this thread

Top Bottom