Dim ex As Object
Dim i As Integer
Dim j As Integer
Dim XlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set XlApp = CreateObject("Excel.Application")
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Dim rst As Recordset
Set Cnn1 = New ADODB.Connection
Cnn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Mode=Read|Write;Persist Security Info=False"
Cnn1.Open
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open SQL, Cnn1, adOpenKeyset, adLockOptimistic, adCmdText
rst.MoveFirst
For j = 0 To rst.RecordCount - 1
For i = 0 To rst.Fields.Count - 1
xlSheet.Cells(1, i + 1) = rst.Fields(i).Name
xlSheet.Cells(j + 2, i + 1) = rst.Fields(i).Value
Next i
rst.MoveNext
Next j
xlSheet.Columns.AutoFit