Solved

Copy List Box to Clipboard

Posted on 2010-11-11
10
1,234 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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