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 record开发者_高级运维set.
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?
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
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"
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论