Option Explicit
Public Sub RunSQLqueryCSV()
' Requires: Microsoft ActiveX Data Objects Library
Dim rsConn As ADODB.Connection
Dim rsData As ADODB.Recordset
Dim strSQL As String
Set rsConn = New ADODB.Connection
rsConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;" & _
"Data Source=[COLOR=red][B]C:\Folder\[/B][/COLOR];"
If rsConn.State <> 1 Then
MsgBox "Connection failed" & Space(15), vbOKOnly + vbExclamation
Exit Sub
End If
strSQL = "SELECT DS1.[COLOR=red][B]Field7Name[/B][/COLOR], DS1.[COLOR=red][B]Field14Name[/B][/COLOR] FROM [COLOR=red][B]import_file.csv[/B][/COLOR] DS1;"
Set rsData = New ADODB.Recordset
rsData.Open strSQL, rsConn, 3, 1, 1
Do Until rsData.EOF
[COLOR=green] ' at this point you have a new row from your input file
[/COLOR] Debug.Print rsData![B][COLOR=#ff0000]Field7Name[/COLOR][/B], rsData![B][COLOR=#ff0000]Field14Name[/COLOR][/B] [COLOR=green]' (for example)[/COLOR]
rsData.MoveNext
Loop
rsData.Close
Set rsData = Nothing
Set rsConn = Nothing
End Sub