Export queries to excel file.

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Hi folks,

Is there a way to export all my queries which left four
characters are "temp" to an excel file called test.xls
form a module?

I have the following queries in my db:

temp1
temp2
temp3
qry1
qry2

I want to export all temp1, temp2 and temp3.... to an
excel file called test.xls. The number of temp query
will be vary every time.

Any help will be appreciated.

Thanks.

Tim.
 
Something like this (loops through the QueryDefs collection) will export
each query onto a separate worksheet in the EXCEL file:

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDefs
Set dbs = CurrentDb()
For Each qdf in dbs.QueryDefs
If Left(qdf.Name, 4) = "temp" Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
qdf.Name, "C:\test.xls"
End If
Next qdf
dbs.Close
Set dbs = Nothing
 
Ken,

Thanks for your help.

Tim.
-----Original Message-----
Something like this (loops through the QueryDefs collection) will export
each query onto a separate worksheet in the EXCEL file:

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDefs
Set dbs = CurrentDb()
For Each qdf in dbs.QueryDefs
If Left(qdf.Name, 4) = "temp" Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
qdf.Name, "C:\test.xls"
End If
Next qdf
dbs.Close
Set dbs = Nothing


--
Ken Snell
<MS ACCESS MVP>





.
 
Back
Top