combine runsql with transferspreadsheet

p0welly

Registered User.
Local time
Today, 00:55
Joined
Aug 26, 2004
Messages
38
in my application I have a number of options where the user can transfer data out of the program into a spreadsheet, I would like to create a dynamic option to do this but Im not really sure how to go about this.

Code:
strSQL = Me.txtSQL.Value
If strSQL Like "Select*" Then
    strSQL = Me.txtSQL.Value
    DoCmd.RunSQL strSQL
    DoCmd.TransferSpreadsheet acExport, , THESQLRESULTGOESHERE, "C:\Program Files\MYAPPLICATION\Exports\sqldump.xls", True
 APPNAME

I thinking something like this, but im guessing it cant be that simple.

Thanks in advance

Andy
 
Figured it out based on this thread.

Code:
On Error Resume Next

Dim db As DAO.Database
Dim qdfNew As QueryDef
Dim strSQL As String
strSQL = Me.txtSQL.Value

Set db = CurrentDb()

With db
.QueryDefs.Delete "qrySQLDump"
Set qdfNew = .CreateQueryDef("qrysqldump", strSQL)
.Close
End With

DoCmd.TransferSpreadsheet acExport, , "QrySQLDump", "C:\Program Files\MYAPPLICATION\Exports\sqldump.xls", True

Seems the easy way is to create a query on the fly and then transfer the query as a spreadsheet
 

Users who are viewing this thread

Back
Top Bottom