Trying to read CSV file and place values into word bookmarks
I have the following code which doesn't seem to do anything on the above.
At this moment in time I'm just trying to read the CSV and use MSG Box to display field values.
Can you please help?
Option Explicit
Private Sub BtnLoad_Click()
On Error GoTo Err_Catch
Err_Catch:
Resume Next
Dim Customer, Salutation, FirstName, Surname, Telephone, Mobile, SiteMobile, EMail, Address1, Address2, Address3, TownCity, _
PostCode, SageNo, CurrentStatus, DTA, SLADate, Services, BagLimit, Charge, ChargePeriod, Sites, strSQL As String
Dim Bookmark, CurrentField As Range
Dim CSVConnection As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set CSVConnection = New ADODB.Connection
Set rs = New ADODB.Recordset
CSVConnection.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
& path & ";Extensions=asc,csv,tab,txt;HDR=NO;Persist Security Info=False"
strSQL = "SELECT * FROM Customer Report.csv"
rs.Open strSQL, CSVConnection, adOpenStatic, adLockReadOnly
Do While Not rs.EOF
MsgBox rs(0)
rs.MoveNext
Loop
If rs.RecordCount > 0 Then
Do
Customer = rs("Customer")
Salutation = rs("Salutation")
FirstName = rs("First Name")
Surname = rs("Surname")
Telephone = rs("Telephone")
Mobile = rs("Mobile")
SiteMobile = rs("Site Mobile")
EMail = rs("EMail")
Address1 = rs("Address 1")
Address2 = rs("Address 2")
Address3 = rs("Address 3")
PostCode = rs("Post Code")
SageNo = rs("Sage Account")
CurrentStatus = rs("Current Status")
DTA = rs("DTA Service")
SLADate = rs("SLA Date")
Services = rs("Current Services")
BagLimit = rs("Bag Limit")
Charge = rs("Charge")
ChargePeriod = rs("Charge Period")
Sites = rs("Sites")
rs.MoveNext
Loop Until rs.EOF
End If
rs.Close
Set CSVConnection = Nothing
End Sub
|