THIS DOESN'T WORK:
sSQL = "select * from qry_ANYQUERY"
DoCmd.TransferSpreadsheet acExport, , sSQL, sFile, True
THIS WORKS:
sSQL = "qry_ANYQUERY"
DoCmd.TransferSpreadsheet acExport, , sSQL, sFile, True
Can anybody help me?
EXAMPLE FOR HOW TO CREATE A NEW QUERY IN ORDER TO
EXPORT IT TO AN EXCEL FILE.
-------------------------
Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim strSQL As String
Const strQName As String = "zExportQuery"
Set dbs = CurrentDb
strSQL = "SELECT * FROM Table_Name;"
Set qdf = dbs.CreateQueryDef(strQName, strSQL)
qdf.Close
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
strQName, "C:\Ken.xls", False
dbs.QueryDefs.Delete strQName
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
--
Ken Snell
<MS ACCESS MVP>
"mauricioff" <mauri...@discussions.microsoft.com> wrote in message
news:0D019824-F11F-47A0...@microsoft.com...
I try to use your code below and it works. But i wish to include the
workbook to be save under a strQName and archived into a folder, the code
below is not doing it. (it just open up the directory for the user to save it
manually)
Any idea to help?
thanks.
=================
Option Compare Database
Sub Testing2()
Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim strSQL As String
Dim strQName As String
strQName = "Year 2007 FC Query by Cust, by CPN-Done by ML"
strSQL = "SELECT * FROM Table_Name;"
DoCmd.OpenQuery strQName
DoCmd.RunCommand acCmdExport
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(strQName)
qdf.Close
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, _
strQName, "C:\Meiling\MISC\MRPbyPN.xls", True -------> 'It is not
saving the wkbk data into the designated folder
MsgBox ("Mission Accomplished!")
dbs.QueryDefs.Delete strQName
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Sub