Home General VB/VBA Connect to .DBF file
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Connect to .DBF file PDF Print E-mail
User Rating: / 0
PoorBest 
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   

 
0 #1 Guest 2011-12-01 23:44
By using this code I get this error message:"[Micro soft][ODBC Visual Foxpro Driver]Function argument value,type or count is invalid". Pl Help.
Quote
 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade