Linking Forms and Reports

To recap an earlier section of forms and subforms, you can set up a form with a nested subform, such that the records that are displayed in the subform are related to the record displayed in the main form. For instance, the main form may show a product, and the subform orders for that product. The subform shows records from an Orders table which match the key value for the Product on display. Rekall typically does this by adding a suitable where term to the SQL query used to retrieve orders from the database.

The nice thing about forms and subforms is that when the user inserts a new record in the subform (ie., in this case inserts a new order record), Rekall stores the correct product key into the order record. This happens completely automatically and you do not have to do anything special for this to occur.

As of Rekall version 2.0.3, this mechanism is extended so that you can do this across multipe forms. To take the above example, suppose that you wanted the product and orders forms to be completely separate, with the product form containing a button that can be clicked to bring up the orders form, showing only orders for that product (and such that you can add new orders just as for the form/subform version).

There are two steps to setting this up. First, in the child form (in this example, the orders form), the Child Field property should be set to the column used for linking, just as in the form/subform version. So, in this example, it would be the column in the Orders table that contains the key value for the corresponding product. When the form is executed, Rekall will construct an SQL where expression based on this column name and the key value passed to the form when it is executed.

The second step to the process is the third argument to the openForm method mentioned above. This should be the value from the parent (ie., here it would be the primary key from the Products table) for the record that is displayed. To do this by hand, you could create a hidden field called (say, linkid) whose display expression is the primary key column, and then use the following code for the OnClick event of a button that opens the orders form:

def eventFunc (button) :
    block = button.getBlock()
    id    = button.getNamedCtrl('../linkid').getValue(block.getQueryRow())
    block.getForm().openForm ('Orders', {}, id)
      

Notice that the code includes an empty dictionary as the second argument to openForm, since the key used to link the forms together must be the third argument.

In practice, there is a quicker way to do this. There is a stock component, called OpenLinkedForm (follow the Execute branch in the component dialog) which will do this for you. This is like the more basic OpenForm component, but takes a third configuration value, which should be the linking expression, typically the primary key column. This is shown in the screenshot below.