Copy query results to the clipboard VBA (1 Viewer)

janz

Registered User.
Local time
Today, 14:01
Joined
Jan 25, 2008
Messages
44
Hi,
I'm trying to copy the outcome of a query to the clipboard.
as follows

DoCmd.OpenQuery "changeboard query", acViewNormal, acEdit
DoCmd.SelectObject acQuery, "CHANGEBOARD QUERY"
RunCommand acCmdCopy
DoCmd.Close acQuery, "Changeboard query", acSaveNo

It doesn't work because in the open query there is nothing selected.
If I select the lines by hand the copy command works fine.

However I can't find the command in VBA to select all the lines in the query.
Can anybody tell me how I can do that?
 

janz

Registered User.
Local time
Today, 14:01
Joined
Jan 25, 2008
Messages
44
Found it the program now looks like this

DoCmd.OpenQuery "changeboard query", acViewNormal, acEdit
DoCmd.SelectObject acQuery, "CHANGEBOARD QUERY"

DoCmd.RunCommand acCmdSelectAllRecords

RunCommand acCmdCopy
DoCmd.Close acQuery, "Changeboard query", acSaveNo

Takes the complete query highlights it and sticks it on the clipboard.
 

dlambert

Member
Local time
Today, 14:01
Joined
Apr 16, 2020
Messages
42
Found it the program now looks like this

DoCmd.OpenQuery "changeboard query", acViewNormal, acEdit
DoCmd.SelectObject acQuery, "CHANGEBOARD QUERY"

DoCmd.RunCommand acCmdSelectAllRecords

RunCommand acCmdCopy
DoCmd.Close acQuery, "Changeboard query", acSaveNo

Takes the complete query highlights it and sticks it on the clipboard.

Thanks a lot for posting the working script on this thread! :D This is (almost) exactly what i am looking for!
The only slight difference i need is to copy the query results WITHOUT the column headings?
Anyone have an idea of how this could be done?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:01
Joined
Oct 29, 2018
Messages
21,467
Thanks a lot for posting the working script on this thread! :D This is (almost) exactly what i am looking for!
The only slight difference i need is to copy the query results WITHOUT the column headings?
Anyone have an idea of how this could be done?
Hi. The way I would probably do it is stick the query result in a Textbox and then copy it to the clipboard.
 

Users who are viewing this thread

Top Bottom