Export Query to Excel

sun_after_rain

Registered User.
Local time
Today, 01:47
Joined
Jun 25, 2011
Messages
11
Hello! I am trying to export specific fields in my search query to excel. My code isn't working: I keep getting "Compile Error: Sub or Function Not Defined" What is wrong?

Private Sub Exportexcel_Click()

Dim strSQL As String
Dim qdf As DAO.QueryDef
strName = GetUserName()
strXLFile = "C:\Documents and Settings\" & strName & "\Desktop\Query.xls"

strSQL = "SELECT title, package, start_date, end_date, license_fee FROM Search_Query"

Set qdf = CurrentDb.CreateQueryDef("tempQuery", strSQL)

CurrentDb.QueryDefs.Append (qdf.Name)

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tempQuery", strXLFile, True
If MsgBox("Do you want to view the file?", vbYesNo) = vbYes Then
FollowHyperlink strXLFile

CurrentDb.QueryDefs.Delete (qdf.Name)

qdf.Close

End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom