Copy List Box to Clipboard

Posted on 2010-11-11
Medium Priority
Last Modified: 2012-05-10
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

Question by:correlate
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
LVL 77

Expert Comment

ID: 34110065
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?
LVL 20

Accepted Solution

darbid73 earned 1000 total points
ID: 34110103
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
LVL 20

Expert Comment

ID: 34110116
this might also help but still relies on the windows API

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.


Author Comment

ID: 34110765
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
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 1000 total points
ID: 34114581
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?


Author Comment

ID: 34114915
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    


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
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34115750
<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.


Author Comment

ID: 34118230
Cool thanks for that

Author Comment

ID: 34122639
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]
    Set rst = Nothing
    If strValue <> "" Then
       strValue = Mid(strValue, 2)
'Paste data to text box
Me.ClipboardText = strValue

'Copy textbox to clipboard
    DoCmd.RunCommand acCmdCopy

Open in new window


Author Closing Comment

ID: 34216428
Sorry for the delay - thought' I'd done the points previously

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question