AW: dBase-Datei einlesen
10.08.2011 09:46:29
bst
Morgen,
Du könntest das auch mit ADO machen.
HTH, Bernd
--
Option Explicit
Sub ReadDBaseFile()
' Connection siehe: http://www.activevb.de/rubriken/faq/faq0091.html
' Datenbank-Treiber
Const JET_ENGINETYPE_DBASE3 = &H10
Const JET_ENGINETYPE_DBASE4 = &H11
Const JET_ENGINETYPE_DBASE5 = &H12
' Settings für die Connection
Const cstrDatabase As String = "C:\TSR\INIT\" ' <--- Pfad anpassen
' Const cstrUsername As String = ""
' Const cstrPassword As String = ""
Dim adoConnection As ADODB.Connection
Dim adoRecordset As ADODB.Recordset
Dim strSQL As String
Dim i As Long
Set adoConnection = New ADODB.Connection
With adoConnection
.Provider = "Microsoft.Jet.OLEDB.4.0"
' .Properties("User ID").Value = cstrUsername
' .Properties("Password").Value = cstrPassword
.Properties("Data Source").Value = cstrDatabase
.Properties("Jet OLEDB:Engine Type").Value = JET_ENGINETYPE_DBASE5
.Open
Debug.Print .ConnectionString
Set adoRecordset = New ADODB.Recordset
strSQL = "SELECT * FROM FEHL1203.dbf" ' <--- SQL Befehl anpassen
' adOpenForwardOnly wäre schneller, liefert aber u.a. keinen Wert für RecordCount !
adoRecordset.Open strSQL, adoConnection, adOpenStatic, adLockReadOnly, adCmdText
' Feldnamen anzeigen
' For i = 0 To adoRecordset.Fields.Count - 1
' Debug.Print i, adoRecordset.Fields(i).Name
' Next
Debug.Print adoRecordset.GetString ' das liefert alle Datensätze als einen String zurück
.Close
End With
' Datenbank-Objekt entfernen
Set adoConnection = Nothing
End Sub