Export undefined queries to excel file

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.
 
C

Clifford Bass

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
 

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

Similar Threads


Top