D
Dave_R
I am using the transferspreadsheet command to export data from access to excel.
Dim strDocName As String
Dim strFileName As String
strDocName = "qryTest"
strFileName = "C:\TestFile.XLS"
strSQL = "SELECT * FROM Table_Name;"
For Each qdef In CurrentDb.QueryDefs
If qdef.Name = strDocName Then 'check if query exists
CurrentDb.QueryDefs.Delete qdef.Name 'delete old query
End If
Next qdef
Set qdf = dbs.CreateQueryDef(strDocName, strSQL)
DoCmd.OpenQuery strDocName, acViewNormal, acEdit 'Open query to run
DoCmd.Close acQuery, strDocName, acSaveYes 'close and save query
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
strDocName, strFileName,True, "A-Z"
It creates a worksheet named A-Z.
If the query is empty, I dont want to export.
How to check if the query is empty?
Dim strDocName As String
Dim strFileName As String
strDocName = "qryTest"
strFileName = "C:\TestFile.XLS"
strSQL = "SELECT * FROM Table_Name;"
For Each qdef In CurrentDb.QueryDefs
If qdef.Name = strDocName Then 'check if query exists
CurrentDb.QueryDefs.Delete qdef.Name 'delete old query
End If
Next qdef
Set qdf = dbs.CreateQueryDef(strDocName, strSQL)
DoCmd.OpenQuery strDocName, acViewNormal, acEdit 'Open query to run
DoCmd.Close acQuery, strDocName, acSaveYes 'close and save query
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
strDocName, strFileName,True, "A-Z"
It creates a worksheet named A-Z.
If the query is empty, I dont want to export.
How to check if the query is empty?