S t r o n a 1 Author: Jacek Kierklo Forms with combo boxes and subforms Introduction The article is intended for high school students getting to know the programs to support databases in particular Microsoft Access. Its aim is to show the principles of creating and using forms that contain more advanced features such as combo boxes and subforms. The problem is shown in the examples, which can be used in the practice of the school. The material discussed in the article can also be a teacher s aid in the discussion of topics on databases. Introduction to the relational model Present database is usually based on the relational model, which assumes that the data can only be positioned in the tables. Since the table is a well-known object for each user, it is easy to learn how to store data. Let us recall that each table in the first row has defined attributes (fields), which are the names of the columns, while the remaining rows (records, tuples) contain data, each row has the same structure. Each table should include data concerning separate object. Since there are various links between objects, so the database tables must be properly connected to each other. The most desirable type of connection (relationship) is a one-to-many (1: N). A one-to-many relationship means that one row of table A corresponds to exactly one row in table B, but one row of table B can correspond to several rows in the table A. There are several methods to bring the structure of the database into a form in which relationships are only one-to-many relationship. This process is called normalization of database. The basis for the creation a one-to-many relationship is the existence of two types of keys: primary key (primary, master) and external key (foreign). The primary key uniquely identifies each row in the table and therefore has a characteristic uniqueness. An external key, in turn, points to a
S t r o n a 2 particular row in the second table, which is provided with a clear connection between the tables. By using a one-to-many relation, we avoid the so-called redundancy or duplication of data, because the data for each animal keeper occur only once in the table, though at least one animal keeper can handle many animals. However, if we viewed only the animal table, it would be difficult to determine who exactly is the animal keeper of every animal. This table is represented by the key Animal keeper, often numerical, that does not give us any information. We need combination with the table of Animal keepers and after identifying the row, retrieving data of a particular person. A form with a combo box The above difficulties in identifying an animal keeper clearly occur in the construction of the form used to display the table Animals. The above difficulties in identifying guardian, clearly occur in the construction of the form used to display the table Animals. The form displays only symbols of animal keepers. Without additional information, we do not
S t r o n a 3 know who is behind the numbers visible here. The solution is to use a combo box, or drop-down list that allows you to choose an animal keeper by their name. In the remainder of this article we will present a step-by-step construction of a combo box. First, go to the Design view, and then remove Animal Keeper text box from the Details box. You could also expand background of the form a little by dragging the right edge a few inches to the right. Before you start, make sure that the wizard is on. Now, we select the Combo Box tool from the menu.
S t r o n a 4 After selecting the tool, the cursor turns into a thin line. It should draw a rectangular frame in the place where you want a surname to appear. When you release the mouse button a wizard combo that launches and leads us through the process. Step 1 At the beginning it should be noted how the combo box is to collect the data. Select the first option - download the values from another table.
S t r o n a 5 Step 2 Now indicate the name of the table - in this case the table Animal keepers Step 3 Now select the fields that will be available on the drop-down list. First check the box, which is the primary key of the Animal keeper table. In our case it is ID_pracownika. It is a unique identification for each adult. Then you can select other fields, but as the name should be the second. This is due to the properties of the combo box that displays the contents of a second field in the sequence list.
S t r o n a 6 Step 4 Now you can choose the order in which names of the animal keepers appear in the list. Step 5 On the screen we can now see how a drop-down list will look like. Here you can set the width of the columns.
S t r o n a 7 Step 6 It's time for the most important step in the whole process. We have to tell the database how the data from the dropdown list are expected to appear in the form. Select "Store this value in the field," and select a box that had been previously removed from the list - here the Opiekun (Animal keeper) field.
S t r o n a 8 Step 7 Finally, choose the name for the combo box that will be visible in the form. Here's the end result of our effort. The form in Design view: and in the operation in the Normal view:
S t r o n a 9 Form with Subform A combo box lets you go back to another table in the direction of the external key to the primary key. This is possible thanks to the properties of the relationship one-to-many relationship. Connection in the reverse direction is also possible. For each animal keeper we want to find all the animals under their care. The solution is to use a subform.
S t r o n a 10 Here is a simple form prepared for the table Animal keeper. In order to make modifications we open the form in Design view and enlarge the canvas to fit the bottom of the list of animals.
S t r o n a 11 On the ribbon, we select the tool Subform / subreport... and draw a rectangle in which we will find a subform on a blank canvas. The subform wizard starts, leading us step by step through the process of creating the control. To construct a subform we will use existing tables.
S t r o n a 12 Select the fields you want to include in the subform. As with combo boxes, here also as the first field, select the primary key column or ID_zwierzęcia (ID_of the animal). The order of the following fields is not so important. Do not change anything in the next window. Note the message at the bottom: "Show Animals for each record in Animal keeper using ID_pracownika (ID_of the animal keeper)
S t r o n a 13 And finally choose the title under which the subform will be visible in the main form. This is the finished form in Design view:
S t r o n a 14 as well as in Normal view:
S t r o n a 15
S t r o n a 16 Summary Examples presented in this article show that you can easily and simultaneously enhance the utility of standard forms. For more complex connections between tables, it may be necessary to use two or more combo boxes in the forms.