Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cannot open *.CSV as ADO Recordset
Message
Information générale
Forum:
Visual Basic
Catégorie:
Bases de données DAO/RDO/ODBC/ADO
Divers
Thread ID:
00409913
Message ID:
00410312
Vues:
19
>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform