Export undefined queries to excel file

  • Thread starter Thread starter Amika
  • Start date Start date
A

Amika

I would like to call customised view and export to excel file for
users to use. However, users have the right to choose what field
should be shown and what table should be included.

Problem comes. Although I can compose the SQL in VBA, however, I
cannot export a excel file from a SQL statement or a recordset.

Anyway I can do so? I cannot export a query or a table because the
query for users may different.
 
Hi Amika,

You can export the results of an SQL statement by saving it as a query.

Public Sub ExportingResultsOfAnSQLStatement()

Dim qd As DAO.QueryDef

Set qd = CurrentDb.CreateQueryDef("qryTemporary Query", _
"select * from [tblSomeTable]")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, qd.Name,
"C:\Temp\Output.xls", True
CurrentDb.QueryDefs.Delete qd.Name
Set qd = Nothing

End Sub

Clifford Bass
 
Back
Top