Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

AutoOpenTables, AutoCloseTables, OpenViews

AutoOpenTables and AutoCloseTables determine whether or not the items listed in the Data environment open and close when the object (form, formset, report, label) opens and closes. OpenViews, added in VFP 5, determines what kind of views get opened by OpenTables.

Usage

lValue = oObject.AutoOpenTables
lValue = oObject.AutoCloseTables

These properties are read-only at runtime, so you need to set them appropriately at design-time—that is, through the Form Designer, Report Designer or Label Designer. There is actually one way to set them programmatically. You can write code that subclasses the DataEnvironment base class. In the subclass definition, you can set these properties the way you want them. But, using a subclassed data environment is not for the faint of heart.

AutoOpenTables and AutoCloseTables interact with OpenTables and CloseTables. OpenTables and CloseTables are methods of the base DataEnvironment class. Their default behavior is to open and close, respectively, all tables and views listed in the DE. You can override or enhance them with your own code if you want.

When AutoOpenTables is .T., OpenTables is called automatically as part of the startup process for the object (form or whatever). Similarly, when AutoCloseTables is .T., CloseTables is called as part of the shutdown sequence. When either AutoOpenTables or AutoCloseTables is .F., the corresponding method is not called automatically.

See OpenTables for a situation where you’d want to turn off AutoOpenTables.

Usage

nValue = oObject.OpenViews

Parameter

Value

Meaning

nValue

0

Open both local and remote views.

1

Open local views only.

2

Open remote views only.

3

Don't open any views.

You usually do want tables in the Data environment to be opened automatically, but views are another story. Depending on the data source and the situation, you may need more control over views, especially in a form. This property gives you some control.

This setting affects not just what happens when OpenTables runs automatically because AutoOpenTables is .T., but also what happens when OpenTables is called explicitly.

See Also

AfterCloseTables, BeforeOpenTables, CloseTables, OpenTables