Microsoft KB Archive/147652

= How to Add a Table to a Form's Data Environment at Run Time =

Article ID: 147652

Article Last Modified on 10/15/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q147652



SUMMARY
A table or view may be added to a Visual FoxPro form at run time. Although you can open a table with the USE command, there are benefits to adding it to the Data Environment of the form. If a form is set to use a Private Data Session, the table will only be added to the Data Environment of the current Data Session.



Step-by-Step Example
 Create a new form by using the Form Designer. Set the DataSession property of the form to 2-Private Data Session.  Add a command button to the form, and place the following code in its Click event: WITH THISFORM.DataEnvironment .ADDOBJECT("mycursor","cursor") .mycursor.Database= SYS(2004)+"samples\data\testdata.dbc" .mycursor.CursorSource="customer" .CloseTables && Closes all the tables and views associated && with the data environment. .OpenTables  && Opens all the tables and views associated && with the data environment. ENDWITH  Save the form. Then run two instances of the form. Click the command button on the first instance of the form, but don't click the command button on the second instance of the form.  In the debug window, type: _SCREEN.ACTIVEFORM.DataEnvironment.mycursor.CursorSource  As you switch between the forms, notice the value in the Debug Window changes according to which DataSession is the active one. The table is only in the Data Environment of the first instance of the form.</li></ol>

Additional query words: VFoxWin

Keywords: kbcode KB147652

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.