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

Last reviewed: February 28, 1996
Article ID: Q147652
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0 and 3.0b

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.

MORE INFORMATION

Step-by-Step Example

  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: kbprg kbhowto kbcode
KBSubcategory: FxprgClassoop


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 28, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.