Results 1 to 2 of 2

Thread: Copy Contents of Listbox to Clipboard

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Copy Contents of Listbox to Clipboard

    How can I copy all the contents of a listbox to a clipboard?

    I have tried loopping though all the contents of the listbox then using the

    VB Code:
    1. DoCmd.RunCommand acCmdCopy

    But doesn't seem to copy everything.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Copy Contents of Listbox to Clipboard

    what are you working in.. Access?
    that command will only copy one line...

    you need to put all the lines in a variable and set that to the clipboard:
    VB Code:
    1. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
    2. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
    3. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    4. Private Declare Function CloseClipboard Lib "User32" () As Long
    5. Private Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
    6. Private Declare Function EmptyClipboard Lib "User32" () As Long
    7. Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    8. Private Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    9. Private Const GHND = &H42
    10. Private Const CF_TEXT = 1
    11. Private Const MAXSIZE = 4096
    12.  
    13. Public Function ClipBoard_SetData(MyString As String)
    14.     Dim hGlobalMemory As Long, lpGlobalMemory As Long
    15.     Dim hClipMemory As Long, X As Long
    16.    
    17.     hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
    18.     lpGlobalMemory = GlobalLock(hGlobalMemory)
    19.    
    20.     lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
    21.     If GlobalUnlock(hGlobalMemory) <> 0 Then
    22.         MsgBox "Could not unlock memory location. Copy aborted."
    23.         GoTo OutOfHere2
    24.     End If
    25.     If OpenClipboard(0&) = 0 Then
    26.         MsgBox "Could not open the Clipboard. Copy aborted."
    27.         Exit Function
    28.     End If
    29.     .
    30.     X = EmptyClipboard()
    31.     hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
    32.    
    33. OutOfHere2:
    34.    
    35.     If CloseClipboard() = 0 Then
    36.         MsgBox "Could not close Clipboard."
    37.     End If
    38.  
    39. End Function
    40.  
    41. Private Sub Command2_Click()
    42.     Dim tmp As String
    43.     For X = 0 To List3.ListCount
    44.         List3.Selected(X) = -1
    45.         tmp = tmp & List3.ItemData(X) & vbCrLf
    46.     Next
    47.     ClipBoard_SetData tmp
    48. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width