VBA/Excel/Access/Word/Access/Text ADO — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:33, 26 мая 2010

Opening a Text File with ADO

 
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