1

I want to export some data in one recordset in Access to Excel.

I know the DoCmd.TransferSpreadsheet command but it works only with stored queries, and in my case it's a runtime-filtered recordset.

I've tried some codes to do what I want. I can get the data exported but I cannot get the column name from the recordset.

Any suggestion on the commands or how to get those column names from recordset?

2 Answers 2

3

DAO recordsets have a name property you can use.

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("SELECT * FROM ARTIKELGRUPPE")
Debug.Print rs.Fields(0).Name
Debug.Print rs.Fields(1).Name

Output for my table:

id
Name
Sign up to request clarification or add additional context in comments.

1 Comment

You can do exactly the same with ADO recordsets, they have the ´name´ property as well.
1

You can alter a stored query prior to calling transfer spreadsheet

Dim myQuery As QueryDef
Set myQuery = CurrentDb.QueryDefs("SampleQuery")
myQuery.SQL = "SELECT * FROM myTable WHERE something"
DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel9, "SampleQuery", "c:\test.xls"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.