Using the code below to extract two fields from a large csv file.
Currently receive an error - "Provider not found" and the words "xlcon.open" is highlighted.
Any insight as to what the cause of the error is and a resolution?
Thanks in advance
Currently receive an error - "Provider not found" and the words "xlcon.open" is highlighted.
Any insight as to what the cause of the error is and a resolution?
Thanks in advance
Code:
Sub GetMyCSVData()
Dim xlcon As ADODB.Connection
Dim xlrs As ADODB.Recordset
Set xlcon = New ADODB.Connection
Set xlrs = New ADODB.Recordset
Dim currentDataFilePath As String
Dim currentDataFileName As String
Dim nextRow As Integer
currentDataFilePath = "C:\Test\"
currentDataFileName = "Feb2019_Purchases"
xlcon.Provider = "Microsoft.Jet.OLEDB.4.0"
'xlcon.Provider = "Microsoft.ACE.OLEDB.12.0" 'Iter 2; did not work
xlcon.ConnectionString = "Data Source=" & currentDataFilePath & ";" & "Extended Properties=""text;HDR=Yes;FMT=Delimited;"""
xlcon.Open
xlrs.Open "SELECT FirstName, Age FROM [" & currentDataFileName & ".csv] WHERE Age > 30 and State = 'Florida' , xlcon"
xlrs.MoveFirst
nextRow = Worksheets("Sheet2").UsedRange.Rows.Count + 1
Worksheets("Sheet2").Cells(nextRow, 1).CopyFromRecordset xlrs
xlrs.Close
xlcon.Close
Set xlrs = Nothing
Set xlcon = Nothing
End Sub