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:
DoCmd.RunCommand acCmdCopy
But doesn't seem to copy everything.
Printable View
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:
DoCmd.RunCommand acCmdCopy
But doesn't seem to copy everything.
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:
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 Public Function ClipBoard_SetData(MyString As String) Dim hGlobalMemory As Long, lpGlobalMemory As Long Dim hClipMemory As Long, X As Long hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1) lpGlobalMemory = GlobalLock(hGlobalMemory) lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString) If GlobalUnlock(hGlobalMemory) <> 0 Then MsgBox "Could not unlock memory location. Copy aborted." GoTo OutOfHere2 End If If OpenClipboard(0&) = 0 Then MsgBox "Could not open the Clipboard. Copy aborted." Exit Function End If . X = EmptyClipboard() hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory) OutOfHere2: If CloseClipboard() = 0 Then MsgBox "Could not close Clipboard." End If End Function Private Sub Command2_Click() Dim tmp As String For X = 0 To List3.ListCount List3.Selected(X) = -1 tmp = tmp & List3.ItemData(X) & vbCrLf Next ClipBoard_SetData tmp End Sub