unclesvenno
Programmer
Gee I'm spending more time looking for help today than actually working! I'm trying to export the results of a query to an excel spreadsheet. Any ideas?
Thanks again,
Uncle Svenno
Thanks again,
Uncle Svenno
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub Command10_Click()
On Error GoTo Eval_Error
MsgBox "Paul - Creating Excel Spreadsheet"
Dim db As Database
Dim qDef As QueryDef
Dim SQL As String
Dim fPath As String
'Set a path and file name!
fPath = "C:\SvennosSample.xls"
Set db = CurrentDb
SQL = "Select * from YourTableNameHere"
'Create qry based on SQL
Set qDef = db.CreateQueryDef("qryTmpExport", SQL)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, ("qryTmpExport"), fPath, True
'Delete the object
DoCmd.SetWarnings False 'Turn-off warning message
'DoCmd.DeleteObject acQuery, "qryTmpExport"
DoCmd.SetWarnings True
Set qDef = Nothing
Set db = Nothing
MsgBox "Paul - Export Complete!"
Exit_Command10_Click:
Exit Sub
Eval_Error:
If Err.Number = 3012 Then 'qry already exists, delete and resume
DoCmd.SetWarnings False 'Turn-off warning message
DoCmd.DeleteObject acQuery, "qryTmpExport"
DoCmd.SetWarnings True
Resume
Else 'Critical Error, display message.
MsgBox Err.Number & " " & Err.Description, vbCritical, "Error"
End If
Resume Exit_Command10_Click
End Sub
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, ("Your Query/Table Name"), fPath, True
Private Sub Data2_Click()
On Error GoTo Eval_Error
Dim db As Database
Dim qDef As QueryDef
Dim SQL As String
Dim fPath As String
'Set a path and file name!
fPath = "C:\Documents and Settings\SG85174\Desktop\Temp.xls"
Set db = CurrentDb
SQL = "Select * from TRIAGE_LOG"
'Create qry based on SQL
Set qDef = db.CreateQueryDef("Data Integrity - No Reas From Level", SQL)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, ("Data Integrity - No Reas From Level"), fPath, True
'Delete the object
DoCmd.SetWarnings False 'Turn-off warning message
'DoCmd.DeleteObject acQuery, "qryTmpExport"
DoCmd.SetWarnings True
Set qDef = Nothing
Set db = Nothing
Exit_Data2_Click:
Exit Sub
Eval_Error:
If Err.Number = 3012 Then 'qry already exists, delete and resume
DoCmd.SetWarnings False 'Turn-off warning message
DoCmd.DeleteObject acQuery, "Data Integrity - No Reas From Level"
DoCmd.SetWarnings True
Resume
Else 'Critical Error, display message.
MsgBox Err.Number & " " & Err.Description, vbCritical, "Error"
End If
Resume Exit_Data2_Click
End Sub