dbTalk Databases Forums  

VBScript Insert into Excel, No error, but no insert either

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss VBScript Insert into Excel, No error, but no insert either in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
effervescent@hotmail.com
 
Posts: n/a

Default 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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.