hi,
how can i export data from a table (access) to the excel?
hi,
how can i export data from a table (access) to the excel?
A number of ways. Manually with the External Data tab, in macro or VBA code using TransferSpreadsheet or in VBA using automation.
i'm usingvba code. and i tried this code:
Sub importtoexcel()
Dim XL As Excel.Application
Dim wbtarget As Workbook
Dim qdfFlintstones As QueryDef
Dim rsFlintstones As Recordset
Set qdfFlintstones = CurrentDb.QueryDefs("t_mes_fec_data")
Set rsFlintstones = qdfFlintstones.OpenRecordset()
Set XL = CreateObject("Excel.Application")
Set wbtarget = XL.Workbooks.Open("G:\OrcControlo\SCC\Joana\Prepar ar_F01Incos02.xlsm")
wbtarget.Worksheets("DCRH_centro_6971").Cells.Clea rContents
wbtarget.Worksheets("DCRH_centro_6971").Cells(1, 1).CopyFromRecordset rsFlintstones
wbtarget.Save
wbtarget.Close
Set wbtarget = Nothing
Set XL = Nothing
Set qdfflintsones = Nothing
End Sub
but the code stops here: Set rsFlintstones = qdfFlintstones.OpenRecordset()
can you explain me why?
You don't need the querydef.
It should work fine by just using:
Set rsFlintstones = currentdb.OpenRecordset("t_mes_fec_data")
But instead of doing all that, look into using the TransferSpreadsheet method:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "t_mes_fec_data", "G:\OrcControlo\SCC\Joana\Prepar ar_F01Incos02.xlsm"
would be a good starting point.