'************************************** ' Name: Text File Connection ' Description:'Connect and execute a SQL ' query in a CSV file 'USE: select [colums] from [name_of_file ' ].csv [where] [order] ' By: vitor m ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None '************************************** Public Function ExecuteCommand(sql As String, Optional strPath As String) As ADODB.Recordset On Error GoTo handle Dim rsResult As ADODB.Recordset If Trim(strPath ) = "" Then strPath = App.Path & "\" End If Set oConn = New ADODB.Connection Set oCommand = New ADODB.Command oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & strPath & ";" & _ "Extended Properties=""text;HDR=YES;FMT=Delimited()""" Set oCommand.ActiveConnection = oConn oCommand.CommandText = sql Set rsResultado = New ADODB.Recordset rsResultado.CursorLocation = adUseClient Set rsResultado = oCommand.Execute If rsResultado.RecordCount > 0 Then rs.MoveFirst Set ExecutarComandoPesquisa = rsResultado 'oConn.Close 'Set oCommand = Nothing 'Set oConn = Nothing Exit Function handle: MsgBox Err.Number & "-" & Err.Description & " (ExecuteCommand)" End Function