the export to excel code is:
' send the query and the sheet name
'usage : Export2XL("qsMyQuery","MyData")
Code:
Public Sub Export2XL(ByVal pvQry, Optional pvCaption)
Dim vDir, vTime, vNam, vFile
If IsMissing(pvCaption) Then pvCaption = pvQry
vDir = txtPath = Environ(“UserProfile”) & "My Documents" 'get the users mydoc path or fill in a network path to save the file
vNam = pvQry
vFile = vDir & vNam & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, pvQry, vFile, True, pvCaption
End Sub