copy/paste but not the whole field

  • Thread starter Thread starter DJ
  • Start date Start date
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?
 
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.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top