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).
MS Access 2002
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).
MS Access 2002
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.
[VBA]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[/VBA]
Hopefully someone else will come along with a better suggestion than mine.
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.
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?
[VBA]
Private Sub Command2_Click()
Text0.SetFocus
Text0.SelLength = Len(Text0.Text)
DoCmd.RunCommand acCmdCopy
End Sub
[/VBA]
HTH
Hey! Now that's much easier.
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
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):
[VBA]
Dim objClipboardTransfer As New DataObject
objClipboardTransfer.SetText Me.tbName.Value
objClipboardTransfer.PutInClipboard[/VBA]
This way you're not actually selecting the text on the screen... and it can be reused in a bunch of different ways.
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
Hi,
The code given by wadiohead 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:[vba]
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
[/vba]
Later...
_________
Groetjes,
Joost Verdaasdonk
M.O.S. Master
Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
(I don't answer questions asked through E-mail or PM's)