25 | 03 | 2017

Connect to .DBF file

You can connect to a DBF file using the Microsoft Visual FoxPro ODBC Driver. (You can download the driver here). Use the code below to access the database and run a SQL string.

'-----------------------------------------------------------------------------
Sub Connect2DBF(ByVal DbasePath As String)
'-----------------------------------------------------------------------------
 
'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
 
Dim oConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim vtsql As String
 
Set oConn = New ADODB.Connection
Set adoRS = New ADODB.Recordset
 
oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
                   "SourceType=DBF;" & _
                   "SourceDB=" & DbasePath & "\;" & _
                   "Exclusive=No;"
 
        vtsql = "SELECT  * FROM g_table"
 
Set adoRS = oConn.Execute(vtsql)
 
 
With adoRS
 
If .RecordCount = 0 Then Exit Do
 
    'Cycle through the records.
    Do
    'Add your code here:
    'Msgbox .fields(0)
    .MoveNext
    Loop Until .EOF = True
 
End With
 
adoRS.Close
oConn.Close
 
End Sub
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2208280
Latest Articles