Berikut ini adalah contoh code di Visual Basic 6 untuk mengexport data yang ada dalam sebuah recordset ke document excel. Langsung ikuti langkah"nya aja yach …!
- Kemudian Ketikkan Code berikut ke dalam class module yang baru saja anda buat tadi
------------------------------------------
Dim rs As ADODB.Recordset
Public Property Let RecordSource(m_rs As Recordset)
Set rs = m_rsEnd Property
Public Sub ExportToExcel()
Dim App As Application
Dim Wb As Workbook
Dim Wk As Worksheet
Dim Baris As Long, Kolom As Integer
Set App = Excel.ApplicationSet Wb = App.Workbooks.AddSet Wk = Wb.Worksheets(1)With rsBaris = 1
Kolom = 0
'mencetak header / nama kolomFor Kolom = 1 To rs.Fields.Count
Wk.Cells(1, Kolom) = rs.Fields(Kolom - 1).Name
Next Kolom'mencetak data dimulai dari record pertama'dan diulang sampai record habis / eof.MoveFirst
While Not .EOF
Baris = Baris + 1
For Kolom = 1 To rs.Fields.Count
Wk.Cells(Baris, Kolom) = rs.Fields(Kolom - 1)
Next Kolom.MoveNext
WendEnd With
'memunculkan aplikasi excelApp.Visible = True'memutus sambungan dengan excelSet Wk = Nothing
Set Wb = Nothing
Set App = Nothing
End Sub- Setelah itu di form buat koneksi dengan database menggunakan object ADODB, setelah itu buat variabel baru sebagai nama class yang baru saja di buat, dilanjutkan dengan mengeset property RecordSource dari class tadi dan berikutnya jalankan method ExportToExcel.

Untuk men DOWNLOAD contoh projectnya klik di SINI
source : vbgue.blogspot.com



