Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Transfer Spreadsheet Command

Status
Not open for further replies.

DanAuber

IS-IT--Management
Apr 28, 2000
255
FR
Is it possible to use the transfer spreadsheet command by specifying the SQL to run rather than referring to a table or query ?

Thus I know that the code below will run query Q1 and ouput it:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"Q1", "C:\temp\my_file.xls", True, ""

But If I have a string "Select * from [Table1]" can I insert that into the TransferSpreadsheet command somehow - if I try:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"Select * from [Table1]", "C:\temp\my_file.xls", True, ""

it falls over....

any help gratefully received

Dan


 
I don't think so. Obviously not if you tried it.

You could specify a query name and then write code to change the SQL property of the query.

Code:
Dim qry as DAO.Querydef

Set qry = Currentdb.Querydefs("qry name")
qry.SQL = "Select * from [Table1]"
Set qry = nothing

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"qry Name", "C:\temp\my_file.xls", True, ""
 
When I run this I get an error on the Dim line: Compile error - User-Defined typed not defined ??

 

While in VBE goto Tools --> References scroll to find and check the reference of the DAO 3.6 library

 
try this

Code:
currentdb.execute INSERT INTO [Excel 8.0;imex=0;hder=yes;DATABASE=c:\filename.xls].[worksheetname$]
SELECT * from Tablename
 
I've just been looking at the TransferSpreadsheet action, and what I've read says that you can not use a SQL string. You must first use the SQL to create a query object, then use that query object in your Transfer action.

-------------------
Rob Foye
Database Management
Regions Bank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top