Cole numa folha de texto e renomeie de .txt para .vbs
Database_Location = "C:\teste.mdb"
Table_Name = "tabela"
Fields_Database = "ID, ReferralID, LeadSite, LeadAccount, LeadCustWONum, SalesResult, DateofSubmit"
todaysdate = now()
OutputFile = "C:\Temp\NewData_" & Replace(FormatDateTime(Now(), vbShortDate) & ".csv", "/", "-")
set objFSO = CreateObject("Scripting.FileSystemObject")
set CSV_Database_Connection = CreateObject("ADODB.Connection")
CSV_Database_Connection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Database_Location & ";Persist Security Info=False"
sSQL = "SELECT " & Fields_Database & " FROM " & Table_Name & " WHERE DateofSubmit >= Date()-1"
Set CSV_Update_Record = CSV_Database_Connection.Execute(sSQL)
Field_Split = Split(Fields_Database, ", ")
Do Until CSV_Update_Record.EOF or CSV_Update_Record.BOF
For X = 0 To Ubound(Field_Split)
Output_Line = Output_Line & CSV_Update_Record(Trim(Field_Split(X))).Value
If X <> Ubound(Field_Split) Then
Output_Line = Output_Line & ","
Else
Output_Line = Output_Line & VbCrLf
End If
Next
CSV_Update_Record.MoveNext
Loop
Set CSV_Update_Record = Nothing
CSV_Database_Connection.Close
Set CSV_Database_Connection = Nothing
Set objFSO = Nothing
set fs = CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile(OutputFile ,true)
f.WriteLine(Output_Line)
f.Close
set f=nothing
set fs=nothing
abraço a todos
Database_Location = "C:\teste.mdb"
Table_Name = "tabela"
Fields_Database = "ID, ReferralID, LeadSite, LeadAccount, LeadCustWONum, SalesResult, DateofSubmit"
todaysdate = now()
OutputFile = "C:\Temp\NewData_" & Replace(FormatDateTime(Now(), vbShortDate) & ".csv", "/", "-")
set objFSO = CreateObject("Scripting.FileSystemObject")
set CSV_Database_Connection = CreateObject("ADODB.Connection")
CSV_Database_Connection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Database_Location & ";Persist Security Info=False"
sSQL = "SELECT " & Fields_Database & " FROM " & Table_Name & " WHERE DateofSubmit >= Date()-1"
Set CSV_Update_Record = CSV_Database_Connection.Execute(sSQL)
Field_Split = Split(Fields_Database, ", ")
Do Until CSV_Update_Record.EOF or CSV_Update_Record.BOF
For X = 0 To Ubound(Field_Split)
Output_Line = Output_Line & CSV_Update_Record(Trim(Field_Split(X))).Value
If X <> Ubound(Field_Split) Then
Output_Line = Output_Line & ","
Else
Output_Line = Output_Line & VbCrLf
End If
Next
CSV_Update_Record.MoveNext
Loop
Set CSV_Update_Record = Nothing
CSV_Database_Connection.Close
Set CSV_Database_Connection = Nothing
Set objFSO = Nothing
set fs = CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile(OutputFile ,true)
f.WriteLine(Output_Line)
f.Close
set f=nothing
set fs=nothing
abraço a todos