Link to home
Create AccountLog in
Avatar of Tom Crowfoot
Tom CrowfootFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

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?
ASKER CERTIFIED SOLUTION
Avatar of darbid73
darbid73
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
this might also help but still relies on the windows API

http://bytes.com/topic/access/answers/517079-copy-string-clipboard
Avatar of Tom Crowfoot

ASKER

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
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
<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
Cool thanks for that
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

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