Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot open *.CSV as ADO Recordset
Message
General information
Forum:
Visual Basic
Category:
Database DAO/RDO/ODBC/ADO
Miscellaneous
Thread ID:
00409913
Message ID:
00410312
Views:
20
>>I am using "Driver={Microsoft Text Driver (*.txt; *.csv)" to open CSV text files as ADO recordsets. It works fine but only if the files have TXT extensions. How can I get it to read files with CSV extensions?
>
>Have you tried specifying the file extension this way: filename#csv?
>
>If not working, please show your code.

Do you mean replacing the period in the file name with pound? Does not work. Here is the code:
Option Explicit
Private oFileConn As ADODB.Connection
Private oRS As ADODB.Recordset
Private Function GetFileRS() As Recordset
    Dim msPath As String, msFile As String, msLine As String, i As Long
    msPath = "P:\FileConversion\"
    msFile = "test.csv"
    Set oFileConn = New Connection
    With oFileConn
      .Mode = adModeReadWrite
      .Open "Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" & msPath & ";DefaultDir=" & msPath & ";Uid=;Pwd=;"
    End With
    Set oRS = New Recordset
    oRS.CursorLocation = adUseClient
    oRS.Open msFile, oFileConn
    oRS.ActiveConnection = Nothing
    Set GetFileRS = oRS
End Function
George
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform