Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA code to copy selected text in Memo field to windows clipboard 2

Status
Not open for further replies.

ACFeddes

Programmer
Jun 18, 2007
11
NL
I'm programming an application in MS Access 2003 / 2007 and would like to know how I can copy highlighted text to the windows clipboard?
I am now using a statement in combination with module "Call ClipBoard_SetData(Memo)" but this copies the whole 'memo' field.
I want to highlight text in the memo field and copy only that text to the clipboard.
 
Have a look at the SelText property of the TextBox object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply, but still don't know where to go from here.

Are you able to give me some VBA?

I tried something like below, but don't know how to pick up selected (higtlighted) text in a Memo field:

Dim strText As String
strText = MyString

RunCommand acCmdCopy
or
ClipBoard_GetData = MyString
ACF
 
How are ya ACFeddes . . .

Have a look here Copy and Paste Data to/from Clipboard


Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks for the info, I had already found that and put to use.

But I come as far as having to use [Ctrl C] to copy selected text to the clipboard and then use a command button to paste that text somewhere else and assign a category to it.

What I want is to make these 2 steps just 1. So in effect the code that runs behind the [Ctrl C] command in windows. I'll paste that in the VBA code and the user has to apply only one keystroke (or click).

Thanks for the info anyway.

ACF
 
ACFeddes . . .

Post what you've tried! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
ACFeddes . . .

After a little testing I've found that [blue]Memo[/blue] fields is [red]completely unsuitable[/red] for your needs! [sad]

However if you don't mind switching to [blue]Rich Text[/blue], two [blue]Rich Text ActiveX Controls[/blue] will fill the bill nicely . . . no muss . . . no fuss . . . you just have to bind the controls to your fields. Nothing else need be done.

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Hello AceMan,
sounds great - switching to Rich Text, two Rich Text ActiveX Controls will fill the bill nicely - you just have to bind the controls to your fields. Nothing else need be done.

How do I do that? Are they available in Access?

I've tried to add Extra controls like:
Microsoft Rich Textbox Control 6.0 (SP4), but gen an error that the control is not supported.

Also the RichText Box Ex.ctlRichEdit, for which it gives the error that I have no rights.

Any idea where I can get these Controls and how to properly install them, so they can be used.

When I deploy the database, will these active controls be included?

Many thanks for your great help so far.

Greetings,
ACF
 
ACFeddes . . .

My prior post was meant for another thread! . . . Sorry about that! [blush]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
As PHV mentioned, SelText should suit:

Code:
Private Sub TheMemo_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MsgBox("Copy?", vbYesNo) = vbYes Then
   Me.CopyField = Me.TheMemo.SelText
End If
End Sub
 
Hello Remou,
that was a great help - thank you very much - so simple really.

I now use it with the module Clipboard_SetData:
Private Sub Memo_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'If MsgBox("Copy?", vbYesNo) = vbYes Then

Call ClipBoard_SetData(Memo.SelText)


' End If
End Sub

Many thanks to all for your efforts and advice.

Greetings & close,
ACF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top