Solved

Copy List Box to Clipboard

Posted on 2010-11-11
10
1,382 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
[X]
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
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 20

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 20

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

689 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