Each form or set of forms includes a data environment. The data environment is an object that includes the tables or views that the form interacts with and the relationships between tables that the form expects. You can use the data environment to automate opening and closing tables and views when the form is run. In addition, you can use the data environment to set the ControlSource property for controls by populating the ControlSource property in the Properties window with all the fields in your data environment.
Adding Tables to the Data Environment
You can visually design the data environment and save it with the form. When you add tables or views to the Data Environment designer, you can see the fields and indexes that belong to the table or view.
To add tables to the data environment
Open the form in the Form Designer.
On the View menu, click Data Environment.
The Data Environment designer opens for the form's data environment.
On the DataEnvironment menu, click Add.
In the Add Table or View dialog box, click the database you want in the Database list.
In the Select area, click Tables or Views.
In the Tables in database list, click the table or view you want to add to the data environment.
Tip: If no database or project is open, click Other to browse for and select a table.
You can also drag a table or view from an open project or the Database Designer to the Data Environment designer.
The following list includes commonly set data environment properties:
Setting Indexes for the Data Environment
You can set the order your records appear in your report by setting an index for the data environment.
To set an index for the Data Environment Designer
From the View menu, choose Data Environment.
From the shortcut menu, choose Properties.
In the Properties Window, choose Cursor1 in the Object box.
Choose the Data tab and select the Order property.
Enter an index name.
- OR -
Select an index from the list of available indexes.
When the Data Environment Designer is active, the Properties window displays objects and properties associated with the data environment. Each table or view in the data environment, each relationship between tables, and the data environment itself is a separate object in the Object box of the Properties window.
Removing Tables from the Data Environment Designer
When you remove a table from the data environment, any relationships that the table is involved in are also removed.
To remove a table or view from the Data Environment Designer
In the Data Environment Designer, select the table or view.
From the DataEnvironment menu, choose Remove.
Setting Relationships in the Data Environment
If you add tables to the Data Environment Designer that have persistent relationships set in a database, the relationships are automatically added in the data environment. If the tables don't have persistent relationships, you can still relate them in the Data Environment Designer.
To set relationships in the Data Environment Designer
Drag a field from the primary table onto the matching index tag in the related table.
You can also drag a field from the primary table to a field in the related table. If there is no index tag in the related table corresponding to the field in the primary table, you're prompted to create the index tag.
Editing Relationships in the Data Environment
When you set a relation in the Data Environment Designer, a line between the tables indicates the relationship.
To edit the properties of the relationship
In the Properties window, select the relationship from the Object box.
The RelationalExpr property is set by default to the name of the primary key field in the primary table. If the related table is indexed on an expression, you need to set the RelationalExpr property to this expression. For example, if the related table is indexed on
UPPER(cust_id), you need to set RelationalExpr to
Setting the OneToMany property of a relation to true (.T.) corresponds to issuing the SET SKIP command. When you skip through the parent table, the record pointer remains on the same parent record until the record pointer moves through all related records in the child table.
|If you want a one-to-many relationship in the form, set the OneToMany property to true (.T.), even if a persistent one-to-many relationship has been established in a database.|