Hello,
I am using Access VBA TransferSpreadsheet acExport to export multiple queries to new spreadsheets and different sheets within those files. Generally, its been working really well.
However, one of the queries, repeats the same query results, over and over, when each query recordset is unique. It is the qryCostData2, per below.
My hunch is that varying numbers of rows in the different queries are the problem. So, will a query with 20 rows of data, have a problem, when the previous range is only 15 rows? Are the ranges getting mixed up somehow? I've tried numerous attempts with different code and still have one query which repeats itself over and over, within the Excel exports. The VBA is looping through many multiple query recordsets.
Would anyone have idea what's wrong? Thank you in advance for any feedback.
Sub ExportToExcel_Loop()
'This exports Access data to the Excel target file:
Dim strFilename As String
strFilename = "C:\TestTargetFile.xlsx"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryCostData2", strFilename, True, "CostRange"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata1", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata2", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata3", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata4", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata5", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata6", strFilename
Call cpyFile_loop
End Sub
I am using Access VBA TransferSpreadsheet acExport to export multiple queries to new spreadsheets and different sheets within those files. Generally, its been working really well.
However, one of the queries, repeats the same query results, over and over, when each query recordset is unique. It is the qryCostData2, per below.
My hunch is that varying numbers of rows in the different queries are the problem. So, will a query with 20 rows of data, have a problem, when the previous range is only 15 rows? Are the ranges getting mixed up somehow? I've tried numerous attempts with different code and still have one query which repeats itself over and over, within the Excel exports. The VBA is looping through many multiple query recordsets.
Would anyone have idea what's wrong? Thank you in advance for any feedback.
Sub ExportToExcel_Loop()
'This exports Access data to the Excel target file:
Dim strFilename As String
strFilename = "C:\TestTargetFile.xlsx"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryCostData2", strFilename, True, "CostRange"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata1", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata2", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata3", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata4", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata5", strFilename
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryProjMetadata6", strFilename
Call cpyFile_loop
End Sub