Welcome to the forums!
Poots has
a post in the code bank of Excel Automation that might be of some use to you.
Based on that, I've done some work like:
Code:
On Error resume next
'instantiate variables
Dim db As DAO.Database, _
rs As DAO.Recordset
Dim exlApp As Excel.Application, _
exlBook As Excel.Workbook, _
exlSheet As Excel.Worksheet
Dim strFilePath As String, _
strExlSheetName As String, _
strFormCurrency As String
Dim intColCnt As Long, _
intRowCnt As Long, _
i As Long, _
j As Long
'Prepare recordset
Set db = Application.CurrentDb
Set rs = db.OpenRecordset(strSQL) 'define this on looping
'Write data to file
'Populate recordset to get accurate record count
If Not rs.EOF Then rs.MoveLast
rs.MoveFirst
'Note: Excel arrays and cells start at 1, not 0, don't deduct 1
intColCnt = rs.Fields.Count
intRowCnt = rs.RecordCount
i = 1
'Write column headings
For j = 0 To (intColCnt - 1)
exlSheet.Cells(1, j + 1).Value = Nz(rs.Fields(j).Name, "")
Next j
'Write recordset data
i = 2
rs.MoveFirst
While Not rs.EOF
For j = 0 To (intColCnt - 1)
exlSheet.Cells(i, j + 1).Value = Nz(rs.Fields(j).Value, "")
Next j
i = i + 1
rs.MoveNext
Wend
I'm sure this could be taken and adapted to your particular needs. You'll just have to put this in your loop and change the SQL every time.
FYI, when I copied this code over I omitted a bunch of other stuff, so I'm not guaranteeing this code will work "as-is", but it should be enough to give you a good start.