Hi Stoneman,
Pass your SQL string to a routine that:
a. Creates a temporary QueryDef based on your SQL
b. Executes your export using the QueryDef
c. Drops the temporary QueryDef when your done
Sub ExportSQL(strSQL As String)
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
On Error GoTo ExportSQL_Err
Set db = CurrentDb
Set qdf = db.CreateQueryDef("qryTemp", strSQL)
qdf.Close
DoCmd.TransferSpreadsheet acExport, , "qryTemp", "C:\Test.xls", True
ExportSQL_Exit:
On Error Resume Next
DoCmd.DeleteObject acQuery, "qryTemp"
qdf.Close
Set qdf = Nothing
db.QueryDefs.Refresh
Set db = Nothing
Exit Sub
ExportSQL_Err:
Resume ExportSQL_Exit
End Sub
(set reference to the DAO library)
HTH,
Bob
|