Private Sub Кнопка2_Click()
Dim strsql, temp1, i, rst As DAO.Recordset
Dim oExcel As Object, oBook As Object, oSheet As Object
'Start a new workbook in Excel
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
strsql = "select Код, Имя, [Кол-во], [Дата], " _
& "val(Таблица1.Работа) as Работа, Адрес, " _
& "val(Таблица1.[Семейное положение]) as [Семейное положение] " _
& "from Таблица1"
Set rst = CurrentDb.OpenRecordset(strsql)
For i = 0 To rst.Fields.Count - 1
oExcel.cells(1, i + 1) = rst.Fields(i).Name
Next
oExcel.cells(2, 1).copyfromrecordset rst
'Save the Workbook and Quit Excel
oBook.SaveAs "D:\Book1.xls"
oExcel.Quit
MsgBox "Готово"
End Sub
|