Автор: artfavourites
Дата сообщения: 15.11.2005 12:25
Код: databaseFile = "somemdb.mdb"
tableToExtract = "sometable"
savedFile = "somecsv.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set csvOutput1 = fso.OpenTextFile(savedFile, 8, True, -2)
cn.Open "Provider=MSDASQL; Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & databaseFile & ";"
rs.Open "SELECT * FROM " & tableToExtract, cn
Do While Not rs.EOF
csvLine = ""
For i = 0 to rs.Fields.Count - 1
If i > 0 Then
csvLine = csvLine & ","
End If
If IsNull(rs.fields(i).value) Then
csvLine = csvLine & """"""
Else
fileldData = CStr(rs.fields(i).value)
fileldData = Replace(fileldData, vbCrLf, "", 1, -1, 1)
fileldData = Replace(fileldData, """", "", 1, -1, 1)
csvLine = csvLine & """" & fileldData & """"
End If
Next
csvOutput1.WriteLine csvLine
rs.MoveNext
Loop
rs.Close
set rs = nothing
csvOutput1.Close