Hi. I'm struggling with a task to parse a CSV into individual fields. I found a topic about this on this forum and others, but implementing the code has not provided the results I expected. Here's my code:
BEGIN CODE
----------------
varAppPath=objFSO.GetParentFolderName(wscript.ScriptFullName) & "\"
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & varAppPath & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
objRecordset.Open "SELECT * FROM Vendors2.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
WScript.Echo objRecordset.Fields("VendorNum").Value
outVenNum = objRecordset.Fields("VendorNum").Value
outVenName = objRecordset.Fields("VendorName").Value
outContact = objRecordset.Fields("Contact").Value
outPhone = objRecordset.Fields("Phone").Value
outAddr2 = objRecordset.Fields("NameAddr2").Value
outAddr3 = objRecordset.Fields("NameAddr3").Value
outAddr4 = objRecordset.Fields("NameAddr4").Value
outAddr5 = objRecordset.Fields("CityST").Value
outPostalCode = objRecordset.Fields("Zip").Value
objRecordset.MoveNext
...
Loop
-------------
END CODE
The problem is that all my out* fields are null, but there is DEFINITELY data in the input CSV file. And the CSV file is in the same dir as the VB script.
Also, it just loops forever. It's like the MoveNext method is not working - it's never reaching the end of the record set.
Please help!
Thanks!
Scott
BEGIN CODE
----------------
varAppPath=objFSO.GetParentFolderName(wscript.ScriptFullName) & "\"
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & varAppPath & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
objRecordset.Open "SELECT * FROM Vendors2.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
WScript.Echo objRecordset.Fields("VendorNum").Value
outVenNum = objRecordset.Fields("VendorNum").Value
outVenName = objRecordset.Fields("VendorName").Value
outContact = objRecordset.Fields("Contact").Value
outPhone = objRecordset.Fields("Phone").Value
outAddr2 = objRecordset.Fields("NameAddr2").Value
outAddr3 = objRecordset.Fields("NameAddr3").Value
outAddr4 = objRecordset.Fields("NameAddr4").Value
outAddr5 = objRecordset.Fields("CityST").Value
outPostalCode = objRecordset.Fields("Zip").Value
objRecordset.MoveNext
...
Loop
-------------
END CODE
The problem is that all my out* fields are null, but there is DEFINITELY data in the input CSV file. And the CSV file is in the same dir as the VB script.
Also, it just loops forever. It's like the MoveNext method is not working - it's never reaching the end of the record set.
Please help!
Thanks!
Scott