Log in

View Full Version : Solved: Fill Win clipboard in MS Access VBA



antonin
09-01-2005, 04:45 AM
I need to copy the content of a textbox into the Windows clipboard, to be used by another application.

Cannot find out how to do it (in VBA code). http://vbaexpress.com/forum/images/smilies/banghead.gif

MS Access 2002

xCav8r
09-02-2005, 08:53 PM
If this can be done in Access, then I don't know how to do it. If you're desperate, send the value to Word and copy it to the clipboard from there.

Private Sub btnCopyToClipboard_Click()
Dim objWord As Word.Application
Set objWord = New Word.Application
DoCmd.Hourglass True
With objWord
.Visible = False
.Documents.Add
.ActiveDocument.Select
.Selection.InsertBefore Me.Text0.Value
.Selection.Copy
.Quit False
End With
DoCmd.Hourglass False
Set objWord = Nothing
End Sub

Hopefully someone else will come along with a better suggestion than mine. :)

antonin
09-02-2005, 11:01 PM
Thank you, that is an interesting idea. I can try this, even though opening Word in the background takes a lot of resources; but, being inspired by this, I know how to fill the clipboard in Visual Basic (as such, not VBA), and the VB6 exe files are much more modest in their demands on the system. However, I am not sure if and how I can open a VB exe in MS Access and pass a value to it.

Tommy
09-03-2005, 08:58 AM
Hi antonin,

I created a form with a textbox named text0, added a commandbutton called command2. The below code copied the text in text0 to the clipboard where I pasted into notepad the text. I think this is what you are asking?


Private Sub Command2_Click()
Text0.SetFocus
Text0.SelLength = Len(Text0.Text)
DoCmd.RunCommand acCmdCopy
End Sub

HTH

xCav8r
09-03-2005, 09:17 AM
Hey! Now that's much easier. ;)

antonin
09-03-2005, 09:38 AM
I have applied the Winword solution and I can live with it. I have tested the "DoCmd.RunCommand acCmdCopy" command, but I have not been able to make it run within my code as-is - perhaps because I assign the textbox's value programmatically. I think I would be able to adapt my code to go along with this approach, but I would have to add a field in the form's layout, and that might be a bit difficult.

Thanks to Tommy anyway. I will remember it for another opportunity.

Antonin

wadiohead
09-06-2005, 09:45 AM
I think there's an even easier solution than that:


In the VBA code, set a reference to Microsoft Forms 2.0 Object Library(unfortunately, in Access, that's not one of the default items, so hit Browse and select "C:\Windows\system32\fm20.dll").

Then place it in the clipboard by using a dataobject (replace "Me.TbName" with your textbox):


Dim objClipboardTransfer As New DataObject
objClipboardTransfer.SetText Me.tbName.Value
objClipboardTransfer.PutInClipboard

This way you're not actually selecting the text on the screen... and it can be reused in a bunch of different ways.

antonin
09-06-2005, 11:52 AM
Great!

That is exacty what I needed; I tried it and it works perfectly.

By the way, I was trying to find something about "how to do it" withut much success - is there any documentation available anywhere, in which such things are described?

Antonin

MOS MASTER
09-06-2005, 01:13 PM
Hi, :hi:

The code given by wadiohead (http://vbaexpress.com/forum/member.php?u=1671) is pretty nifty. (Well done)

But I do think the sollution by Tommy is the true VBA sollution for this problem.

I tested it with pasting it in Word like:
Private Sub Knop20_Click()
Dim oWord As Object
With Doc_Titel
.SetFocus
.SelLength = Len(Doc_Titel.Text)
End With

DoCmd.RunCommand acCmdCopy

Set oWord = CreateObject("Word.Application")
With oWord
.Visible = True
.documents.Add
.selection.paste
End With
Set oWord = Nothing
End Sub


Later...:whistle: