Public Function CSVExport(db As DAO.Database, sSQL As String, sDest As String) As Boolean
' #VBIDEUtils#************************************************************
' * Programmer Name : Jarot Dian
' * Web Site : www.belajar-pemrograman-vbonline.blogspot.com
' * E-Mail : cybersoft83@gmail.com
' * Module Name : Database_Module
' * Module Filename : Database.bas
' * Procedure Name : CSVExport
' * Parameters :
' * db As DAO.Database
' * sSQL As String
' * sDest As String
' **********************************************************************
' * Comments : Export sql data to a CSV File
' *
' *
' **********************************************************************
Dim record As Recordset
Dim nI As Long
Dim nJ As Long
Dim nFile As Integer
Dim sTmp As String
On Error GoTo Err_Handler
Set record = db.OpenRecordset(sSQL, DAO.dbOpenDynaset, DAO.dbReadOnly)
' *** Open output file
nFile = FreeFile
Open sDest For Output As #nFile
' *** Export fields name
For nI = 0 To record.Fields.Count - 1
sTmp = "" & (record.Fields(nI).Name)
Write #nFile, sTmp;
Next
Write #nFile,
If record.RecordCount > 0 Then
record.MoveLast
record.MoveFirst
For nI = 1 To record.RecordCount
For nJ = 0 To record.Fields.Count - 1
sTmp = "" & (record.Fields(nJ))
Write #nFile, sTmp;
Next
Write #nFile,
record.MoveNext
Next
End If
Close #nFile
CSVExport = True
Exit Function
Err_Handler:
MsgBox ("Error: " & Err.Description)
CSVExport = False
End Function
' #VBIDEUtils#************************************************************
' * Programmer Name : Jarot Dian
' * Web Site : www.belajar-pemrograman-vbonline.blogspot.com
' * E-Mail : cybersoft83@gmail.com
' * Module Name : Database_Module
' * Module Filename : Database.bas
' * Procedure Name : CSVExport
' * Parameters :
' * db As DAO.Database
' * sSQL As String
' * sDest As String
' **********************************************************************
' * Comments : Export sql data to a CSV File
' *
' *
' **********************************************************************
Dim record As Recordset
Dim nI As Long
Dim nJ As Long
Dim nFile As Integer
Dim sTmp As String
On Error GoTo Err_Handler
Set record = db.OpenRecordset(sSQL, DAO.dbOpenDynaset, DAO.dbReadOnly)
' *** Open output file
nFile = FreeFile
Open sDest For Output As #nFile
' *** Export fields name
For nI = 0 To record.Fields.Count - 1
sTmp = "" & (record.Fields(nI).Name)
Write #nFile, sTmp;
Next
Write #nFile,
If record.RecordCount > 0 Then
record.MoveLast
record.MoveFirst
For nI = 1 To record.RecordCount
For nJ = 0 To record.Fields.Count - 1
sTmp = "" & (record.Fields(nJ))
Write #nFile, sTmp;
Next
Write #nFile,
record.MoveNext
Next
End If
Close #nFile
CSVExport = True
Exit Function
Err_Handler:
MsgBox ("Error: " & Err.Description)
CSVExport = False
End Function
1 comments:
mo tnya bro...ini caranya masukin data sqlnya gimana ya?? mohon petunjuknya dong...
klo berkenan jawabnya via email ke ariefato@gmail.com
terimkasih bnyak sebelumnya ya.....
Posting Komentar