[AccessD] copy string to clipboard

Jim Lawrence accessd at shaw.ca
Thu Aug 18 01:25:02 CDT 2005


Hi Bruce:

I have some code that I have been using for years, mostly for debugging
purposes. It just copies a string up into the clip board and it doesn't look
as ugly as the code from Terry Kreft.

The following code resides in a miodule declaration area:

<code>
'Whole bunch of APIs which allow text to be copied to clipboard...
Private Declare Function OpenClipboard Lib "User32" (ByVal hWnd&) As Long
Private Declare Function EmptyClipboard Lib "User32" () As Long
Private Declare Function GetClipboardData Lib "User32" (ByVal wFormat&) As
Long
Private Declare Function SetClipboardData Lib "User32" (ByVal wFormat&, _
        ByVal hMem&) As Long
Private Declare Function CloseClipboard Lib "User32" () As Long
'
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags&, _
        ByVal dwBytes&) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem&) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem&) As Long
'
Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
        ByVal lpString2 As Any) As Long
</code>

And the remainder is place in a module's function area:

<code>
Public Sub ClipPutText(lsText As String)
    ' Stores text on the clipboard

    Dim hMem As Long
    Const GHND = &H42
    
    hMem = GlobalAlloc(GHND, Len(lsText) + 1)
    lstrcpy GlobalLock(hMem), lsText
    If GlobalUnlock(hMem) = 0 Then
        If OpenClipboard(0&) <> 0 Then
            EmptyClipboard
            SetClipboardData 1, hMem
            CloseClipboard
        End If
    End If
    
End Sub
</code>

And it can be called from anywhere; forms, reports or modules like so:

ClipPutText MyString  'Place the string 'MyString into the clipboard


HTH
Jim
 
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Bruen, Bruce
Sent: Wednesday, August 17, 2005 7:29 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] copy string to clipboard

This must! be simple.
 
I have a string variable created by concatenating the values of several
form fields.  So how can I copy the value of this string to the
clipboard?
 
Private Sub Command35_Click()
    Dim refstr As String
    refstr = "RCRef=|" & Me.ucref & "|" & Me.testname & "|" & Me.TestID
& "|"
    Debug.Print refstr
    Stop
    ':-( Runcmd accmdStickTheStringInTheClipboard :-(
End Sub
 
tia 
bruce
 
 
This e-mail and any attachments may contain confidential information that is
intended solely for the use of the intended recipient and may be subject to
copyright. If you receive this e-mail in error, please notify the sender
immediately and delete the e-mail and its attachments from your system.  You
must not disclose, copy or use any part of this e-mail if you are not the
intended recipient.  Any opinion expressed in this e-mail and any
attachments is not an opinion of RailCorp unless stated or apparent from its
content. RailCorp is not responsible for any unauthorised alterations to
this e-mail or any attachments. RailCorp will not incur any liability
resulting directly or indirectly as a result of the recipient accessing any
of the attached files that may contain a virus.
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list