Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy a query result from access in the clipboard, without the headers

Status
Not open for further replies.

lancemakali

Technical User
Mar 13, 2009
8
NL
Hi everyone,

I believe this has been posted before, but not exactly in the same way I want it, and even then, the solution I've seen so far haven't been helpful in any ways yet.
I honestly searched a lot for the answer today, everywhere I could think of, but since I'm no VB specialist I thought it was now time to ask.

In short:
I have this MDB file that contains 1 table and 2 queries. The result of the query named 'OUTPUT' is something I need to copy and paste into a SAP form which has the same columns order etc....
BUT, if I copy from the Access query result then the column headers are pasted as well, and that is not accepted by our SAP system obviously, so it's bit of a pain in the @ss.

I'm attaching a sample of what I did so far (zipped: 41Kb)
I was thinking that the user would enter the DB, run the OUTPUT query and that the result would be put in the clipboard without the headers.
That would be enough for us.
If we now do a select all and then copy from the query result, the headers are there as well, you can paste in notepad, you'll see immediatly.
Other solutions welcome if more feasible, I don't care if there's a crap code behind, as long as it does the job ^^

Well, thanks in advance for helping out :)

Cheers
Larry
 
Hi,

Thanks for that.
But this looks quite a complex thing to me.... and I'm not using HTML nor ASP.
I said SAP, it's not a typo ^^

But basically, forget the SAP part, if you copy/paste the quer result in notepad, same happens, columns headers are there, and I just don't want that.

Hope this clarifies;
Cheers
Larry
 
try this code
Code:
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Select * from OUTPUT ", CurrentProject.Connection
Open "c:\a.txt" For Output As #1
Print #1, rst.GetString(, , , vbCrLf)
Close #1
rst.Close
Set rst = Nothing
FollowHyperlink "c:\a.txt"
 



Here's an option for you.

COPY the SQL from the query.

Open Excel.

Data > Import External Data > New Database Query... and open a connection to your MS Access database.

PASTE your SQL code into MS Query SQL button window.

Execute the query

Select ALL

Edit > Copy Special -- Uncheck INCLUDE COLUMN HEADINGS

Alternatively, Select All and COPY in MS Access. Paste into an Excel sheet and COPY the data only.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



BTW, you can specify the Data Range Properties of the Querytable in Excel to EXCLUDE headings. Once your have inserted a QT in Excel, all you need do is Data > Refresh to execute the query to your Access table(s) and get new data.

So the ONGOING process would be...

Open Excel

You can also set a property to execute the query when you open the workbook, or do it manually -- Data > Refresh.

Copy the data.

VOLA!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks, guys, I'll give this a go later on today or tomorrow :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top