Solved

Copy List Box to Clipboard

Posted on 2010-11-11
10
1,181 Views
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

0
Comment
Question by:correlate
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 77

Expert Comment

by:peter57r
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?
0
 
LVL 19

Accepted Solution

by:
darbid73 earned 250 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
0
 
LVL 19

Expert Comment

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

http://bytes.com/topic/access/answers/517079-copy-string-clipboard
0
 

Author Comment

by:correlate
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
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 250 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?

JeffCoachman
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:correlate
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    

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
 
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.

JeffCoachman
0
 

Author Comment

by:correlate
ID: 34118230
Cool thanks for that
0
 

Author Comment

by:correlate
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]

       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
 

Author Closing Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now