Philip1
10-21-2016, 06:07 AM
Hi All.
I have the following code which doesn't seem to work.
Can any please asssist?
At the moment I'm just trying to read the CSV file and use msgbox to display field values:
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
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
I have the following code which doesn't seem to work.
Can any please asssist?
At the moment I'm just trying to read the CSV file and use msgbox to display field values:
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
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