How to: Set Up a One-to-Many Form Using the Grid Control
One of the most common uses for a grid is to display the child records for a table while text boxes display the data for the parent records. When the user moves through the records in the parent table, the grid displays the appropriate child records.
If you have a data environment for your form that includes a one-to-many relationship between two tables, displaying the one-to-many relationship in the form is very easy.
To set up a one-to-many form with a data environment
Drag desired fields from the parent table in the Data Environment Designer to your form.
Drag the related table from the Data Environment Designer to the form.
In almost all cases, you will want to create a data environment for your form or form set. However, it is not much more complicated to create a one-to-many form without using the Data Environment Designer.
To set up a one-to-many form without creating a data environment
Add text boxes to your form to display the desired fields from the primary table.
Set the ControlSource Property of the text boxes to the primary table.
Add a grid to the form.
Set the RecordSource Property of the grid to the name of the related table.
Set the LinkMaster Property of the grid to the name of the primary table.
Set the ChildOrder Property of the grid to the name of the index tag in the related table that corresponds to the relational expression of the primary table.
Set the RelationalExpr Property of the grid to the expression that joins the related table to the primary table. For example, if the ChildOrder tag is indexed on "lastname + firstname", set RelationalExpr to the same expression.
Either way you set up the one-to-many form, you can add navigation controls to move through the parent table and refresh the form objects. For example, the following code could be included in the Click Event of a command button:
SELECT orders && if orders is the parent table
SKIP
IF EOF( )
GO BOTTOM
ENDIF
THISFORM.Refresh
See Also
Tasks
How to: Set the Source of the Data Displayed in the Grid
How to: Display Controls in Grid Columns
How to: Make Controls Easier to Use
Concepts
Controls and Objects Created in Earlier Versions
Reference
Controls for Manipulating Rows of Data