ID: Q147652
3.00 3.00b WINDOWS
kbhowto
The information in this article applies to:
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.
1. Create a new form by using the Form Designer.
2. Set the DataSession property of the form to 2-Private Data Session.
3. 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
4. Save the form. Then run two instances of the form.
5. 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.
6. In the debug window, type:
_SCREEN.ACTIVEFORM.DataEnvironment.mycursor.CursorSource
7. 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.
Additional reference words: 3.00 3.00b VFoxWin
KBCategory: kbhowto
KBSubcategory: FxprgClassoop
Keywords : kbcode kbVFp300 kbVFp300b kbVFp600 FxprgClassoop
Version : 3.00 3.00b
Platform : WINDOWS
Last Reviewed: November 2, 1998