| Connect to .DBF file |
|
|
|
| Tutorials | |||
| Written by Administrator | |||
|
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. [code] '-----------------------------------------------------------------------------
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
[/code]
|



Comments
RSS feed for comments to this post