DoCmd.TransferSpreadsheet acExport.......

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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"
 
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"
 
Back
Top