PRB: Formset.LOAD Is Not the First Event to Fire

Last reviewed: April 30, 1996
Article ID: Q129571
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SYMPTOMS

When a form set contains a Data Environment, the BeforeOpenTables event and the OpenTables method of the Data Environment are triggered before the Load event of the form set. This article explains the reason behind this implementation and offers a workaround if you want the Load event to execute before the tables are opened.

CAUSE

The Load event of a form set usually sets the environment of a form. In particular, it can be used to bind data to controls on a form. Therefore, in most cases, tables and views must be loaded before the LOAD event of a form set is executed. Thus, the OpenTables method of the data environment is, by default, called before the Load event of the form set is executed.

WORKAROUND

If you do not want the tables or views to be opened when the Load event of a form set is executed, set the AutoOpenTables property of the form to .F.. You can then call the OpenTables method of the data environment to open the tables automatically. For example, use the following command in any method of the form:

   THISFORMSET.DataEnvironment.Opentables

STATUS

This behavior is by design.

MORE INFORMATION

Following is the sequence of events that are executed when a form set created in Visual FoxPro version 3.0 is loaded or unloaded. The order of events might differ if the form is converted from a FoxPro version 2.x screen. In this example, the form set is named FORMSET1 and contains a form named FORM1 and a data environment called DATAENVIRONMENT. This list was generated by executing the following code for the following events and methods:

   ACTIVATE SCREEN
   ?PROGRAM()

   FORMSET1.LOAD
   .DATAENVIRONMENT.OPENTABLES
   .DATAENVIRONMENT.BEFOREOPENTABLES
   FORMSET1.FORM1.LOAD
   FORMSET1.DATAENVIRONMENT.INIT
   FORMSET1.FORM1.INIT
   FORMSET1.INIT
   FORMSET1.SHOW
   FORMSET1.ACTIVATE
   FORMSET1.FORM1.ACTIVATE
   FORMSET1.FORM1.GOTFOCUS
   FORMSET1.FORM1.QUERYUNLOAD
   FORMSET1.DESTROY
   FORMSET1.FORM1.DESTROY
   FORMSET1.FORM1.UNLOAD
   FORMSET1.UNLOAD
   FORMSET1.DATAENVIRONMENT.CLOSETABLES
   FORMSET1.DATAENVIRONMENT.AFTERCLOSETABLES
   FORMSET1.DATAENVIRONMENT.DESTROY

NOTE: The OPENTABLES method calls the BEFOREPOPENTABLES event before the tables are actually opened. However, the code in the event handler is executed before the tables are opened, and this is the reason why OPENTABLES prints before BEFOREOPENTABLES prints.

For more information about the sequence of events that are triggered when a form runs, execute the sample program called EVENTS.SCX located in the SAMPLES\CONTROLS\EVENTS directory.


Additional reference words: 3.00 VFoxWin
KBCategory: kbtool kbprb
KBSubcategory: FxtoolFormdes


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: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.