Selected text of TextBox -> string

Selected text of TextBox -> string

Post by SGVucn » Fri, 03 Feb 2006 03:47:27


how can I optain the marked text within a TextBox ?
 
 
 

Selected text of TextBox -> string

Post by Dirk Goldg » Fri, 03 Feb 2006 04:04:48


While the text is selected -- which means while the text box has the
focus -- the control's .SelStart and .SelLength properties tell where
the selection begins and how long it is, so you can use them to extract
the selected substring from the .Text property:

With Me.txtMyTextbox
If .SelLength > 0 Then
strSelected = Mid$(.Text, .SelStart + 1, .SelLength)
Else
strSelected = vbNullString
End If
End With

However, when the control loses the focus, the selection will be lost.
So if you want to have this information available in some other event,
you may need to capture it in the control's Exit event, before the focus
is lost, and store it in a module-level variable.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
 
 

Selected text of TextBox -> string

Post by Marshall B » Fri, 03 Feb 2006 05:41:40


With the focus restrictions that Dirk explains, there is
also the SelText proverty.

--
Marsh
MVP [MS Access]
 
 
 

Selected text of TextBox -> string

Post by Dirk Goldg » Fri, 03 Feb 2006 05:49:05


D'oh! I forgot about that!

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)