Related Forms and Related Pages FAQ's

If my One-to-Many or Related Pages form is not functioning properly, what should I check?

These forms rely on two things to make them function properly: relations in the DataEnvironment, if using tables, and Referential Integrity being set up for foreign key field(s) in the Data Builder.

When setting up Referential Integrity:

∑       Make sure there is a PK tag (called VPM Primary) selected for both the parent and child cursors (tables/views/cursoradapters) in the Data Builder.

∑       Make sure there is a FK tag created for the child cursor and that it is selected on the Integrity page for the FK field.

∑       Make sure that the FK field(s) of the child cursor and PK field(s) of the parent cursor are the same type and width.

∑       If there is more than one FK field (compound FK), set up RI identically for both fields.

When setting up relations for tables (not applicable to views and cursoradapters):

∑       Make sure that the relation is set from parent table into child table.

∑       If the relation expression involves more than one field, make sure the RelationalExpr property of the relation is correct (field1+field2+Ö).

∑       Make sure the correct tag is selected for the relation. The relation expression must be at the beginning of the tagís index expression. This is the tag specified in the ChildOrder property of the relation, not the Order property of the child table. If a tag is specified in the Order property of the child table, it is ignored.

∑       Make sure the OneToMany property of the relation is set to .F..

From a Related Forms child form, how do I access the parent record selected on the parent form?

The trick is to switch to the datasession used by the parent form, access the data, and then switch back to the child formís datasession. See the following code for an example of how this can be done:

* Save datasession ID of child form

lnCDSID = _SCREEN.ActiveForm.DataSessionID

SET DATASESSION TO (_SCREEN.oApp.aActiveForms(_SCREEN.ActiveForm.nParentFormRow,6))

* Save current work area number of parent form

lnPArea = SELECT()

* Make sure the work area of parent form ISA is selected

SELECT (_SCREEN.oApp.aActiveForms(_SCREEN.Activeform.nParentFormRow,4))

* Your code here

* Re-select work area in parent form datasession

SELECT (lnPArea)

* Switch back to datasession of child form

SET DATASESSION TO (lnCDSID)

How can I customize the Toolbar List Grid for cursors on a Related Pages form?

The List dialog is always brought up for the active cursor. So, on any page of a Related Pages pageframe, the List dialog will be brought up for the table being edited on that page. The List dialog always uses the contents of the cListCaptions, cListFields, and cListTags form properties to tell it what information to display and how to display it. When the Activate event of the Related Pages form is run, values for these three properties for each cursor are stored in the aRelatedPgf array property of the form. Then, when a page is activated, the values for these three properties are moved from the array to the form properties. See the Form_Toolbar_RelatedPages section in the Form Classes chapter of the Technical Reference manual for a description of this array. For the child, grandchild, etc. cursors, the default values for these three properties are determined so that the List will include each field in the active (master) tag. If you want to modify these default List definitions, you can place code in the form's Activate event that places values into the appropriate row in aRelatedPgf. For example, if you had 3 pages, your Activate code would be:

DODEFAULT()

ThisForm.aRelatedPgf(2,10) = <cListCaptions for page 2 cursor>

ThisForm.aRelatedPgf(2,11) = <cListFields for page 2 cursor >

ThisForm.aRelatedPgf(2,12) = <cListTags for page 2 cursor >

ThisForm.aRelatedPgf(3,10) = <cListCaptions for page 3 cursor >

ThisForm.aRelatedPgf(3,11) = <cListFields for page 3 cursor >

ThisForm.aRelatedPgf(3,12) = <cListTags for page 3 cursor >

To determine what the values should be for these three properties for a given cursor, do the following:

1.   Select the cursor as the InitialSelectedAlias.

2.   Run the List Builder, creating the List definition for that cursor.

3.   The three form properties will now contain the values that you need to place in aRelatedPgf as described above.

4.   When finished, make sure you reset the ISA to the parent cursor and reset the three properties to the values appropriate for the parent cursor. The values in these properties for the parent (ISA) cursor are automatically placed into the first row of aRelatedPgf so there is no need to include code for row one in the Activate event.

More:

Grid FAQ's