Microsoft KB Archive/172592

= How To Open a Visual FoxPro Table for Read/Write =

Article ID: 172592

Article Last Modified on 7/2/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q172592



SUMMARY
FoxPro 2.x tables can be opened as read/write under DAO. Following the same procedure for Visual FoxPro tables will open the tables as read only. ISAM drivers are being used under DAO. The following method will open free tables and tables that are part of a Visual FoxPro database as read/write with RDO. In addition to providing read/write access to these files, the ODBC driver also provides greater performance than the Installable ISAM driver.

If data validity checks are not made, Visual FoxPro database integrity could be violated for tables that are part of a database.



MORE INFORMATION
 Create a form with two text boxes and 5 CommandButtons. Be sure to select the Remote Data Object under References for the Project. Place the following captions on command1 through command5 buttons:

"edit"

"update"

"quit"

">"

"<"  Place the following code in the General Declarations section of the form's code: Option Explicit Dim cn As New rdoConnection Dim rs As rdoResultset Dim SQL As String

Private Sub Command1_Click rs.edit End Sub

Private Sub Command2_Click rs(1) = Text2.Text rs.Update End Sub

Private Sub Command3_Click rs.Close Set rs = Nothing cn.Close Set cn = Nothing Unload Me     End Sub

Private Sub Command4_Click

rs.MoveNext If Not (rs.EOF) Then Text1.Text = rs(0) Text2.Text = rs(1) Else rs.MoveLast End If    End Sub

Private Sub Command5_Click rs.MovePrevious If Not (rs.BOF) Then Text1.Text = rs(0) Text2.Text = rs(1) Else rs.MoveFirst End If     End Sub

Private Sub Form_Load '       ' Using a DSN-less connection to open a free table '       cn.Connect = "SourceType=DBF;" _ & "SourceDB=C:\Vfp\Samples\Data;" _ & "Driver={Microsoft Visual FoxPro Driver}"

cn.CursorDriver = rdUseOdbc cn.EstablishConnection "rdDriverNoPrompt"

SQL = "select * from customer"  'this should be a free table Set rs = cn.OpenResultset(SQL, rdOpenKeyset, rdConcurRowVer)

rs.MoveFirst Text1.Text = rs(0) Text2.Text = rs(1) End Sub

 Press the F5 key to run the form. Make changes by editing text box 2, pressing edit, and then updating. Verify that changes have been made to the table by running the form several times.

NOTE: The Source in the connect statement above will need to be altered for your system. Source points to a directory containing the table.

