Question : Need Advice using VBA with Access to copy to Clipboard.

Greetings Experts,

In my Access 2002 project, I'm looking for a way to copy a string variable or the contents of a textbox to the Clipboard.

I've researched various methods and none seem to work.  I've tried using the Clipboard object method but get an error message: Can't find Object.  I've also tried the Sendkeys method, but also can't get it to work.
I know Sendkeys is rather sloppy, but ^C is really simple.  My problem may lie with the way SelText is working. When I run the code, the contents of the textbox is highlighted and selected.

I'm rather scared of the long coding methods I've read about using Functions and APIs.

I don't neccessarily want to use the old stand by - manually hitting ctl_A and ctl_C, I just want it automatic to the Clipboard.

Can anyone shed any light on the matter?

Andrew

Answer : Need Advice using VBA with Access to copy to Clipboard.

You can add the code below to its own module - I named my module Clipboard then you use code like:

  Clipboard.SetText me.txtAddress & ", " & me.txtCity

Make sure to add reference to fm20.dll - I think is installed on most machines with Office installed. See http://support.microsoft.com/kb/224305 for details.

The code below only works with text.

When do you mean by 'automatic'?




1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Option Compare Database
Option Explicit
' needs reference to Microsftsoft Forms 2.0 fm20.dll
Sub test()
    SetText "xyzzy"
    MsgBox GetText
    Clear
End Sub
 
Public Sub Clear()
    Dim obj As New DataObject
    obj.SetText ""
    obj.PutInClipboard
End Sub
 
Public Sub SetText(ClipText As String)
    Dim obj As New DataObject
    obj.SetText ClipText, 1
    obj.PutInClipboard
End Sub
 
Public Function GetText() As String
    Dim obj As New DataObject
    obj.GetFromClipboard
    GetText = obj.GetText
End Function
Open in New Window Select All
Random Solutions  
 
programming4us programming4us