Douglas J. Steele said:
Try something like:
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim qdfCurr As DAO.QueryDef
Dim strFileName As String
Dim strFolder As String
Dim strSQL As String
strFolder = "C:\SomeFolderName\"
Set dbCurr = CurrentDb
' Change the names in the SQL
Set rsCurr = CurrentDb.OpenRecordset _
("SELECT KeyField FROM MyTable")
Do While rsCurr.EOF = False
' Change the names in the SQL
strSQL = "SELECT KeyField, Field1, Field2, Field3 " & _
"FROM MyTable " & _
"WHERE KeyField = " & rs.KeyField
strFileName = KeyField & ".xls"
' Make sure the file doesn't already exist
If Len(Dir(strFolder & strFileName)) > 0 Then
Kill strFolder & strFileName
End If
' qryTemp must already exist.
Set qdfCurr = dbCurr.QueryDefs("qryTemp")
qdfCurr.SQL = strSQL
qdfCurr.Close
DoCmd.TransferSpreadsheet acExport, , , _
"qryTemp", strFolder & strFileName
rsCurr.MoveNext
Loop
rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing