VBScript Insert into Excel, No error, but no insert either -
11-05-2004
, 05:59 PM
Hi,
The following script does not give me any errors, but it does not
generate any data in the file. Could someone tell me what I'm doing
wrong? I know the recordset contains data, because immediately after
this, i am using the same recordset to generate a csv. Thanks - Mike
Option Explicit
'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************
Function Main()
Dim con
Dim xlsConnectionString
xlsConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& DTSGlobalVariables("StandardXLSTemplateLocation"). Value & ";Extended
Properties=Excel 8.0;"
Dim rsData
Set rsData = CreateObject("ADODB.Recordset")
Set rsData = (DTSGlobalVariables("rsClientData").Value).Clone()
Set con = CreateObject("ADODB.Connection")
Do While Not (rsData.eof)
con.Open xlsConnectionString
con.Execute "INSERT INTO StandardXLSData " & _
"(" & _
"[DateTime], " & _
"[First Name], " & _
"[Last Name], " & _
"[email], " & _
"[Home Phone], " & _
"[Work Phone], " & _
"[Street Address], " & _
"[City], " & _
"[State], " & _
"[Zip], " & _
"[Comments]" & _
")" & _
" VALUES" & _
"(" & _
"'" & rsData.Fields("DateTime").Value & "'," & _
"'" & StripTicks(rsData.Fields("First Name").Value) & "'," & _
"'" & StripTicks(rsData.Fields("Last Name").Value) & "'," & _
"'" & StripTicks(rsData.Fields("Email").Value) & "'," & _
"'" & rsData.Fields("Home Phone").Value & "'," & _
"'" & rsData.Fields("Work Phone").Value & "'," & _
"'" & StripTicks(rsData.Fields("Street Address").Value) & "'," &
_
"'" & StripTicks(rsData.Fields("City").Value) & "'," & _
"'" & rsData.Fields("State").Value & "'," & _
"'" & rsData.Fields("Zip").Value & "'," & _
"'" & StripTicks(rsData.Fields("Comments").Value) & "'" & _
")"
con.Close
rsData.MoveNext
Loop
rsData.Close
Set rsData = Nothing
Set con = Nothing
Main = DTSTaskExecResult_Success
End Function
Function StripTicks(v)
v = Replace(v, "'", "")
StripTicks = v
End Function |