Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    9

    Question Unanswered: How can Copy an Image to Clipboard??

    Hi all,
    I need a serious, serious problem.
    In my access form I create an image with a Barcode ActiveX Control, after that I need to copy this Barcode (as a picture) to clipboard, to paste it in a Word document or in an Excel sheet.

    How can I do that????

  2. #2
    Join Date
    Sep 2003
    Location
    Birmingham, UK
    Posts
    121
    As far as I'm aware to get anything to the clipboard thru Access is a 'bit of a mare' and requires a series of API calls. I've attached the code I use below to get a string to the clipboard but I'm not sure if it will work with images and haven't got time to try it at the mo.


    ''''''''Declare the API's'''''''''
    Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Private Declare Function CloseClipboard Lib "User32" () As Long
    Private Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "User32" () As Long
    Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    Private Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Private Const GHND = &H42
    Private Const CF_TEXT = 1
    Private Const MAXSIZE = 4096


    ''''''''''Function to get the string to the clipboard''''''''''
    Public Function ClipBoard_SetData(MyString As String)
    Dim hGlobalMemory As Long, lpGlobalMemory As Long
    Dim hClipMemory As Long, X As Long

    ' Allocate moveable global memory.
    '-------------------------------------------
    hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)

    ' Lock the block to get a far pointer
    ' to this memory.
    lpGlobalMemory = GlobalLock(hGlobalMemory)

    ' Copy the string to this global memory.
    lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)

    ' Unlock the memory.
    If GlobalUnlock(hGlobalMemory) <> 0 Then
    MsgBox "Could not unlock memory location. Copy aborted."
    GoTo OutOfHere2
    End If

    ' Open the Clipboard to copy data to.
    If OpenClipboard(0&) = 0 Then
    MsgBox "Could not open the Clipboard. Copy aborted."
    Exit Function
    End If

    ' Clear the Clipboard.
    X = EmptyClipboard()

    ' Copy the data to the Clipboard.
    hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

    OutOfHere2:

    If CloseClipboard() = 0 Then
    MsgBox "Could not close Clipboard."
    End If

    End Function

    '''''''''''Call the clipboard function
    Clipboard_Setdata (mystring)

    Lemme know if this helps (or if you find another way!!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •