DoCmd.TransferSpreadsheet acExport.......

B

Bob Barnes

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"TheQueryName", N, "Sheet1"

Where "N" is a concatenated Excel Filename.

I would like to get "TheQueryName" ONLY from a string I write, since there
will be many "variable" Queries determined by any of 15 True/False Fields
being True (only ONE of them being True)...I have no problem writing the
String of the SQL..Can that string be "substituted" for the Query Name
argument, IE, "TheQueryName"???

TIA - Bob
 
D

Douglas J. Steele

No, it must be the name of a table or query.

However, you could rewrite the SQL of the query:

Dim qdfCurr As DAO.QueryDef
Dim strSQL As String

strSQL = "SELECT ....."

Set qdfCurr = CurrentDb.QueryDefs("TheQueryName")
qdfCurr.SQL = strSQL

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"TheQueryName", N, "Sheet1"
 
B

Bob Barnes

BEAUTIFUL - Thank you Doug - Bob

Douglas J. Steele said:
No, it must be the name of a table or query.

However, you could rewrite the SQL of the query:

Dim qdfCurr As DAO.QueryDef
Dim strSQL As String

strSQL = "SELECT ....."

Set qdfCurr = CurrentDb.QueryDefs("TheQueryName")
qdfCurr.SQL = strSQL

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"TheQueryName", N, "Sheet1"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top