MyTetra Share
Делитесь знаниями!
Opening a Text File with ADO
Время создания: 16.03.2019 23:43
Текстовые метки: VBA_Access, Connection
Раздел: !Закладки - VBA - Access
Запись: xintrea/mytetra_db_adgaver_new/master/base/14839664602qubkdh40k/text.html на raw.githubusercontent.com

Sub Open_TextFile()

   Dim conn As ADODB.Connection

   Dim rst As ADODB.Recordset

   Dim fld As ADODB.Field

    Dim strPath As String: strPath = "<path_to_folder_or_file>"

   

   Set conn = New ADODB.Connection

   Debug.Print conn.ConnectionString

   conn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & _

   "DBQ=" & strPath & "\"

       Set rst = New ADODB.Recordset

   rst.Open "select * from [10_1_DPU.txt]", conn, adOpenStatic, _

       adLockReadOnly, adCmdText

   Do Until rst.EOF

       For Each fld In rst.Fields

          Debug.Print fld.Name & "=" & fld.Value

       Next fld

       rst.MoveNext

   Loop

   rst.Close

   Set rst = Nothing

   conn.Close

   Set conn = Nothing

End Sub

 

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 

Sub Open_TextFile()

   Dim conn As ADODB.Connection

   Dim rst As ADODB.Recordset

   Dim fld As ADODB.Field

 

   Set conn = New ADODB.Connection

   Debug.Print conn.ConnectionString

   conn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & _

   "DBQ=" & CurrentProject.Path & "\"

       Set rst = New ADODB.Recordset

   rst.Open "select * from [Employees.txt]", conn, adOpenStatic, _

       adLockReadOnly, adCmdText

   Do Until rst.EOF

       For Each fld In rst.Fields

          Debug.Print fld.Name & "=" & fld.Value

       Next fld

       rst.MoveNext

   Loop

   rst.Close

   Set rst = Nothing

   conn.Close

   Set conn = Nothing

End Sub

 

Так же в этом разделе:
 
MyTetra Share v.0.58
Яндекс индекс цитирования