Or you could build a "just-in-tim" query, as they say, with something like:
Code:
Private Sub Form_Unload(Cancel As Integer)
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb()
'Delete the existing JIT query;
'trap the error if the query does not exist.
On Error Resume Next
db.QueryDefs.Delete ("qryFormData")
On Error GoTo 0
Set db = CurrentDb()
Set qd = db.CreateQueryDef("qryFormData")
qd.SQL = "SELECT ID, " _
& "Field1, " _
& "Field2 " _
& "FROM tblRecords " _
& "WHERE ID = " & Me.txtID '<-- Use form control as parameter
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryFormData", "C:\Book1.xls"
db.QueryDefs.Delete ("qryFormData")
End Sub
Reason I prefer the code approach I posted first is it gives me more control over where my export data ends up. It works with an existing workbook, accounts for coulmn headings, appends data to pre-existing data, and lets you easily select the sheet to append to. And if I want to use a template I can just add a little more code, etc. The DoCmd methods like TransferSpreadsheet and OutputTo acQuery all seem to overwrite existing workbooks or data, or open new workbooks, etc. I could never get them to get my data where I wanted it, so I don't use them. Maybe someone else has had better luck with them.
Bob