Subforms |
|
Overview of Subforms |
Introduction |
Relational database allows you to separate data in objects so that these objects can hold different pieces of information and make data available to other objects that need it. Sooner or later, users constantly need information held by one form while they are working on another form. There are various ways you can solve such a problem. One solution is to "embed" one form or report into another form or report. A subform is a form that you position inside of another form. In order to "include" one form into another form, both objects must have a relationship, as we have learned in the past. The form that is hosting the other form is the parent. The form that is added to the parent is called the child form. The parent form must have a primary key that "links" or relates it to a foreign key in the child form. This foreign key of the child object must be of the same data type as the primary key on the parent object. |
Microsoft Access >= 2000 Automatic Subforms |
Microsoft Access 2000 and later versions allow you to quickly create a form that has a subform already. Before using this feature, you should make sure that the table you want to use has a sub datasheet, which can be verified by the + button on the left of its records: As you may know already, a sub datasheet exists if a relationship had previously been created between two tables. Using this feature, to create a form that is automatically equipped with a subform, after selecting the table on the Database Window, on the Database toolbar, you can click the arrow of the New Object button and select AutoForm. |
Practical Learning: Automatically creating a Form With a Subform
Automatic Forms |
As done with all the other forms we have used so far, there are two main techniques you can use to create a subform. Keeping the tradition of its many wizards, Microsoft Access provides the means of automatically creating a subform. There is no particular design you need to follow for a subform. A subform is primarily a form. The only true rule you must follow is that one of its fields must have a field, usually its primary key, that will allow it to be related to a field on the form in which it would be added. If you are not using the Form Wizard, you can still design a form and make it a subform.
You can also create a form equipped with a subform, using the Form Wizard. To do this, in the first page of the wizard, select the parent form. Select the necessary fields for the form (report). In the Tables/Queries combo box, select another table or query that holds the fields for the child form (report). Continue with the wizard. The wizard will verify that the tables or queries share a relationship. If they do not, you would receive an error or the result of the form (report) would be unpredictable.
Practical Learning: Automatically Creating an Auto-Subform
Types of Subforms |
Introduction |
Microsoft Access provides various techniques to create a subform. We saw above how a form can be created automatically with a subform. This is sometimes referred to as Master-Detail. Besides using the wizards, you can also design a subform. Subforms typically come in three layouts and each can be used for a specific purpose. |
Practical Learning: Introducing Subform Design
|
The Datasheet Form |
The automatically created forms and reports provide a simplistic design. Instead of generating such form, or after creating them, you can design or redesign your subforms. To support this, there are three types of layout you can use for a subform. |
Such a form is designed like any other. To get the spreadsheet display, select the form in Design View and, in the Properties window, change its Default View to Datasheet. |
Practical Learning: Using a Datasheet Subform
|
The Single Form |
A single form is the type of form that displays its data one record at a time. This concept, which was used on most forms we have used so far, can also be applied to a subform. The single layout can be valuable if you want to show one record from a related form as it is linked to a record on the current form. While a Datasheet form can clearly show that it is an embedded object, the fields of a single form can easily be mixed with those of the hosting form but it is usually determined to be apart. A single subform is designed like a regular form where fields are created in the Detail section and other optional controls can be added to the other sections of the form. When selecting the fields that would be part of the subform, make sure you include only those that can be useful in the form that will host the subform. |
Practical Learning: Designing a Single Subform
|
The Continuous Form |
Microsoft Access provides another type of table, sometimes more flexible: the Continuous form. Like the Datasheet form, the Continuous form displays as many records as the height of the form can afford. While the fields of a Datasheet are usually “reproduced” as they would be on the source table, the fields of a Continuous form must be (carefully) designed to play their roles. We saw that a single form displays the values that belong to a record and only one record displays on the form. Here is an example: |
Practical Learning: Designing a Subform or Subreport
|
MOUS Topics |
Exercises |
Watts A Loan
|
Yugo National Bank
|
|
||
Previous | Copyright © 2002-2019, FunctionX | Next |
|