OutputTo Action

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

Guest

Is it possible to use the OutputTo action on a SQL
statement created on-the-fly? I can get it to export from
a saved query, but I can't figure out the code to get it
to work from a SQL statement.

Any help would be greately appreciated!!
 
You can do this by creating a temporary query, saving it, exporting it, and
then deleting it.

Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim intLoop As Integer
Dim strSQL As String, strQ As String
strQ = "QueryName"
Set dbs = CurrentDb
strSQL = "SELECT * FROM Table_Name WHERE (etc.)"
Set qdf = dbs.CreateQueryDef(strQ, strSQL)
qdf.Close
DoCmd.OutputTo acOutputQuery, strQ, acFormatTXT, _
"C:\MyFolder\MyFile.txt"
dbs.QueryDefs.Delete strQ
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
 
Back
Top