copy/paste but not the whole field

D

DJ

I need users to be able to highlight a section of text in a text box, copy to
clipboard and paste to another field on the form. I am currently Using a
button to previouscontrol setfocus then acCmdCopy, then another button
alongside the receiving field using acCmdPaste. Unfortunately, this selects
the whole field though, not the highlighted section

How would I do this?
 
L

Lars Brownie

From a previous post by Richard Rost:

You can use the .SelStart and .SelLength properties of a textbox to figure
out what text the user has selected. Unfortunately, you have to be ON the
textbox (it has to have focus) in order to use these properties, and as soon
as you LEAVE the text box, the selection is lost (unlike in VB6 where the
selection actually remains).

So what I did was to create a second text box that I called SelectedText.
You can hide it if you want. Then, using the OnMouseUp event of the primary
text box (the one I want to search on - called LastName) I simply dropped
the selected text into this new box:

' Private Sub LastName_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
' SelectedText = Mid(LastName, LastName.SelStart + 1,
LastName.SelLength)
' End Sub

The MouseUp event fires when you release the left mouse button, or just
after the user selects his text, which places the text itself in the
SelectedText textbox. Now you have your search text.
 
D

DJ

That works just fine. Thanks very much!

Lars Brownie said:
From a previous post by Richard Rost:

You can use the .SelStart and .SelLength properties of a textbox to figure
out what text the user has selected. Unfortunately, you have to be ON the
textbox (it has to have focus) in order to use these properties, and as soon
as you LEAVE the text box, the selection is lost (unlike in VB6 where the
selection actually remains).

So what I did was to create a second text box that I called SelectedText.
You can hide it if you want. Then, using the OnMouseUp event of the primary
text box (the one I want to search on - called LastName) I simply dropped
the selected text into this new box:

' Private Sub LastName_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
' SelectedText = Mid(LastName, LastName.SelStart + 1,
LastName.SelLength)
' End Sub

The MouseUp event fires when you release the left mouse button, or just
after the user selects his text, which places the text itself in the
SelectedText textbox. Now you have your search text.
 
Top