VBA/Excel/Access/Word/Access/dBASE ADO

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

Open dBase file and query data

 
Sub Open_dBase_DSNLess()
   Dim conn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Set conn = New ADODB.Connection
   conn.Open "DRIVER={Microsoft dBase Driver (*.dbf)};" & "DBQ=" & CurrentProject.Path & "\"
   Debug.Print conn.ConnectionString
   Set rst = New ADODB.Recordset
   rst.Open "Select * From Customer.dbf", conn, adOpenStatic, adLockReadOnly, adCmdText
   Do Until rst.EOF
      Debug.Print rst.Fields(1).Value
      rst.MoveNext
   Loop
   rst.Close
   Set rst = Nothing
   conn.Close
   Set conn = Nothing
End Sub



Opening a dBASE file with ADO

 
Sub Open_dBaseFile()
   Dim conn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Set conn = New ADODB.Connection
   conn.Open "Provider=MSDASQL;DSN=MyDbaseFile;"
   Set rst = New ADODB.Recordset
   rst.Open "Customer.dbf", conn, , , adCmdTable
   Do Until rst.EOF
      Debug.Print rst.Fields(1).Value
      rst.MoveNext
   Loop
   rst.Close
   Set rst = Nothing
   conn.Close
   Set conn = Nothing
End Sub