Copy List Box to Clipboard

Dear Experts,

Does anyone have a piece of code to copy the contents of a list box to clipboard?

The list box is called "PaymentType", the data comes from "Qry-Stats-Payment-Type".

Many thanks

correlateAsked:
Who is Participating?
 
darbid73Connect With a Mentor Commented:
If the text is selected in the control then you can simply use

RunCommand acCmdCopy

USING VBA to copy to the clipboard otherwise is not that easy (or as easy as Vb6) as far as I understand

see here http://www.everythingaccess.com/tutorials.asp?ID=Copying-data-to-and-from-the-Clipboard-%28Acc-1-2%29

Source Allen Browne
0
 
peter57rCommented:
I don't really get what you want here..

Are you trying to capture an image of the listbox as it appears on your form?
Or are you trying to capture the contents of Qry-Stats-Payment-Type?
Or are you trying to copy the selected record(s) in listbox to the clipboard?
Or something else?
0
 
darbid73Commented:
this might also help but still relies on the windows API

http://bytes.com/topic/access/answers/517079-copy-string-clipboard
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
correlateAuthor Commented:
Guys sorry about the delay - went into what was supposed to be a 20 minute meeting & onyl just got out - as far as what i am trying to achive isa simple copy of the data, so that could come from the underlying query - will give give these suggestions a go now
0
 
Jeffrey CoachmanConnect With a Mentor MIS LiasonCommented:
Again, not enough info.

Suppose you select 5 out of the 10 Items in the list box?
Do you want all the items copied or just the selected Items?

Besides, in order for any selections to be copied, they must be be Selected.
In which case you would probably need to loop all the items, even then, you cannot simply "Copy" this data to the clip board.
I may be missing something though...

If the list is coming from a query you will have better luck copying the data from there.

Remember, the more time you invest in taking time to correctly form your question, the faster we can propose solutions.
Sound fair?

JeffCoachman
0
 
correlateAuthor Commented:
Fair enough, for clarity I would like to be able to copy all the data, so I will retry the copy query method -  the code I originally found for this worked sporadically and hence the question.  The other ideas I had and you may be able to save me a lot of grief trying are ...

1. if there was a way of either "selecting all" in the list box (or from the underlying query) could this be then put into a single text box and then copied    

Or

2. Is there a way to create a create a table or query using vba with the consolidated results in a single field. That way I can set the control source of a text box to show that and copy from there?

Many thanks
0
 
Jeffrey CoachmanMIS LiasonCommented:
<1. if there was a way of either "selecting all" in the list box (or from the underlying query) could this be then put into a single text box and then copied    >
Not "Easily"

<2. Is there a way to create a create a table or query using vba with the consolidated results in a single field. That way I can set the control source of a text box to show that and copy from there?>
Again, Not "Easily".

Remember, we do not know your skill level here, so while what you are asking is possible, it may not be what you consider "Simple".

The deal with a listbox is that it holds values in an "Array".
You cant simple do a "Select All-->Copy" of this type of data.

So please consider the "Copy directly form the query" technique I listed in addition to the previous suggestions.

JeffCoachman
0
 
correlateAuthor Commented:
Cool thanks for that
0
 
correlateAuthor Commented:
Guys Thanks for you help - using a mixture of boag2000 comments & also the copy from text box solution darbid73 we have a solution.  Basically I was able to copy the relevant column in the underlying query, place the result in a hidden text box & then copy the textbox (code Below)
'Copy query data
Dim rst As Recordset
Dim strValue As String
 
    strValue = ""
    Set rst = CurrentDb.OpenRecordset("Qry-Stats-Payment-Type")
    Do While Not rst.EOF
       strValue = strValue & vbCrLf & rst![TextBox]
       rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing
 
    If strValue <> "" Then
       strValue = Mid(strValue, 2)
       
'Paste data to text box
Me.ClipboardText = strValue


'Copy textbox to clipboard
Me.ClipboardText.SetFocus
    DoCmd.RunCommand acCmdCopy

Open in new window

0
 
correlateAuthor Commented:
Sorry for the delay - thought' I'd done the points previously
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.