I have some code I cobbled together that sort of writes a RecordSet to Excel. What I really need is to write Query results to Excel so that I get my headings/field names.
Both Access and Excel are version 2007.
I was using
but it blew up worse. Does Access 2007 recognize the new file extensions in Excel?
Alan
Both Access and Excel are version 2007.
Code:
Private Sub ExportModel_Click()
Dim intStart As Integer
Dim appXL As Excel.Application
Dim rst As DAO.Recordset
Dim DBs As DAO.Database
[COLOR=red] 'Exports data to Excel and formats for Asset Report[/color]
Set appXL = New Excel.Application
Set DBs = CurrentDb
Set rst = DBs.OpenRecordset("qryMulti_model")
appXL.Workbooks.Open "c:\book1.xlsx"
appXL.Cells(1, 1).Select
appXL.ActiveSheet.Range("A1").CopyFromRecordset rst
With appXL
.Worksheets(1).Select
.ActiveSheet.Paste
[COLOR=red]' .ActiveSheet.UsedRange.Select[/color]
.Selection.Copy
.Range("C8").Select
.Selection.PasteSpecial Transpose:=True
End With
Set appXL = Nothing
[COLOR=red]' When does Excel show me what it did ??[/color]
End Sub
Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, _
"qryMulti_model", "test.xltm", -1
Alan