================================================================
Here is some sample code that should work as a template for you. I have pieced this together from various places, so I hope I got all the variables named right.
Dim fADO_Connect As ADODB.Connection
Dim fRst_RecSet As ADODB.Recordset
Dim fExl_Appl As Excel.Application
Dim fExl_WrkBook As Excel.Workbook
Dim fExl_WrkSheet As Excel.Worksheet
Dim lInt_RowID As Integer
Dim lStr_RowID As String
dim
' Establish and Open Connection
Set fADO_Connect = New ADODB.Connection
fADO_Connect.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=<IP Address>;" & _
"DATABASE=<Database Name>;" & _
"UID=<UserID>;PWD=<Password>; OPTION=35"
fADO_Connect.Open
If (fADO_Connect.State = adStateOpen) Then
' Create and Generate the RecordSet
Set fRst_RecSet = New ADODB.Recordset
fRst_RecSet.Open "<SQL Query>", fADO_Connect, adOpenKeyset, adLockOptimistic, adCmdText
If ((fRst_RecSet.BOF = False) Or (fRst_RecSet.EOF = False)) Then
' Instantiate Excel Application
Set fExl_Appl = CreateObject("Excel.Application"

If Not (fExl_Appl Is Nothing) Then
' Instantiate Workbook
Set fExl_WrkBook = fExl_Appl.Workbooks.Add
If Not (fExl_WrkBook Is Nothing) Then
' Instantiate WorkSheet
Set fExl_WrkSheet = fExl_WrkBook.Worksheets(1)
If Not (fExl_WrkSheet Is Nothing) Then
' Activate the Worksheet
fExl_WrkSheet.Activate
lInt_RowID = 0
' Loop thru the Recordset
lRst_RecSet.MoveFirst
Do While (lRst_RecSet.EOF = False)
' Set the Current Excel Row
lInt_RowID = lInt_RowID + 1
lStr_RowID = Trim(lInt_RowID)
' Copy RecordSet Data into Excel Cells
fExl_WrkSheet.Range("A" & lStr_RowID).Value = fRst_RecSet.Fields("Field1"

.Value
fExl_WrkSheet.Range("B" & lStr_RowID).Value = fRst_RecSet.Fields("Field2"

.Value
fExl_WrkSheet.Range("C" & lStr_RowID).Value = fRst_RecSet.Fields("Field3"

.Value
...
' Get Next Recordset Record
fRst_RecSet.MoveNext
Loop
' Save the new Spreadsheet
fExl_WrkBook.SaveAs "c:\NewBook.xls"
Else
MsgBox "Unable to Create WorkSheet"
End If
Else
MsgBox "Unable to Create Workbook"
End If
Else
MsgBox "Unable to Instantiate Excel"
End If
Else
MsgBox "No Record to Report"
End If
Else
MsgBox "Unable to Establish Connection"
End If
' Clean Up
If Not (fExl_WrkSheet Is Nothing) Then
Set fExl_WrkSheet = Nothing
End If
If Not (fExl_WrkBook Is Nothing) Then
fExl_WrkBook.Close
Set fExl_WrkBook = Nothing
End If
If Not (fExl_Appl Is Nothing) Then
fExl_Appl.Workbooks.Close
fExl_Appl.Quit
Set fExl_Appl = Nothing
End If
If (fRst_RecSet.State = adStateOpen) Then
fRst_RecSet.Close
End If
Set fRst_RecSet = Nothing
If (fADO_Connect.State <> adStateClosed) Then
fADO_Connect.Close
End If
Set fADO_Connect = Nothing
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein