Subforms
Home FAQ Getting Started Tables Queries Forms Reports Macros/VBA

 

Form Wizard
Manual Forms
Subforms
Switchboard

Step Number 1

Now we are going to create a form with a subform. This speeds data entry and keeps you from having to open numerous child forms in order to edit related data. First, we need to fix the Recipes table so that it has a few more fields on it. Right click on tblRecipes and select Design View from the menu that drops down.

Figure 1 - Click here to view a larger version of the image.

Step Number 2

You should remember how to add fields to add table from the earlier tutorials. Do so, until you have the fields shown below in the Recipes table.

Figure 2 - Click here to view a larger version of the image.

Step Number 3

Now, close and save the table. Once you are back to the database window, click on Forms to bring up a list of the forms in this database project. Select Create Form by Using Wizard.

Figure 3 - Click here to view a larger version of the image.

Step Number 4

You should recognize this first window of the Form Wizard. Select tblRecipes in the combo box

Figure 4 - Click here to view a larger version of the image.

Step Number 5

Select all of the fields in this table to display on the form.

Figure 5 - Click here to view a larger version of the image.

Step Number 6

Select tblRecipeIngredients. You don't actually want to add any of these fields, since it is the linking table between the Ingredients table and the Recipes table.

Figure 6 - Click here to view a larger version of the image.

Step Number 7

Now select tblIngredients from the combo box and add the IngredientName field to the form. Then click Next.

Figure 7 - Click here to view a larger version of the image.

Step Number 8

In the next window, make sure that you have the form displaying your data by tblRecipes. The recipes table is the master table, while the ingredients table is the child table (meaning that your form will display only the records in the ingredients table that correspond to a given record in the Recipes table). Be sure that the Form with subform(s) option is selected. Click Next.

Figure 8 - Click here to view a larger version of the image.

Step Number 9

In the next step of the wizard, Access will ask you about the layout you want for the subform. Be sure that you have selected the Tabular layout. Click Next.

Figure 9 - Click here to view a larger version of the image.

Step Number 10

For the form style, I chose standard. I personally find background http://academic.lipscomb.edu/access/images to be distracting. However, you may choose a different style if you find one that you like. Click Next

Figure 10 - Click here to view a larger version of the image.

Step Number 11

In the next window that comes up, be sure that you have named your form frmRecipes and your subform frmRecipeIngredients. Now, click Finish.

Figure 11 - Click here to view a larger version of the image.

Step Number 12

Access produced a form that doesn't look too bad, but you may need to move some things around to make it look right. We'll fix these things next.

Figure 12 - Click here to view a larger version of the image.

Step Number 13

Switch to design view. You should see the window below. We need to fix the spacing on several of the control labels and also fix the size of the subform (Access messes this up more often than it gets it right, so you should make sure you are familiar with moving and resizing controls - it will only get worse when you work with multiple subforms).

Figure 13 - Click here to view a larger version of the image.

Step Number 14

Since you have already worked with designing forms manually, it should be a fairly simple matter for you to rearrange the controls on the form (and resize the form) until it looks like the image below.

Figure 14 - Click here to view a larger version of the image.

Step Number 15

We also need to rearrange the controls on the subform. It should be IngredientName, Quantity, then Comments. Access didn't do this very well either, but at least it set up the subform and put the controls in place. You can rearrange these controls the same way you did when manually designing a form, but you will need to drag the labels separately from the fields, since they are in different parts of the form.

Figure 15 - Click here to view a larger version of the image.

Step Number 16

Now take a look at the form in View mode. It looks a lot better than it did before, but we still need to modify it to make it look right. Switch back to design view.

Figure 16 - Click here to view a larger version of the image.

Step Number 17

Right-click in the little box in the upper left hand corner of the subform, as shown below and select Properties from the popup menu.

Figure 17 - Click here to view a larger version of the image.

Step Number 18

Find the item labeled Navigation Buttons and set it to No.

Figure 18 - Click here to view a larger version of the image.

Step Number 19

Do the same for dividing lines, since they serve no useful purpose.

Figure 19 - Click here to view a larger version of the image.

Step Number 20

Try clicking on the subform now. Note that the properties in the properties window are different now. The window now contains the properties of the subform and its label as a unit, rather than just the subform itself. We aren't going to do anything with this, I just thought it important that you take a look at what was there, in case it ever shows up when you were intending to work on just the subform.

Figure 20 - Click here to view a larger version of the image.

Step Number 21

Now click on the square in the upper left corner of the Recipe form. The data in the properties window will change again. Now we can start editing the properties of the main form to make it look better.

Figure 21 - Click here to view a larger version of the image.

Step Number 22

First, take out the dividing lines. No one knows why Access puts those there; they only seem to clutter the form.

Figure 22 - Click here to view a larger version of the image.

Step Number 23

Next, select Scrollbars and tell it that you don't want any. Why would you, on a form that displays only a single record at a time.

Figure 23 - Click here to view a larger version of the image.

Step Number 24

Now, we will continue working on the subform. First, click on the subform and find the Border Style property. Change it to Transparent, since we really don't want a wierd-looking border around our subform anyway.

Figure 24 - Click here to view a larger version of the image.

Step Number 25

Now, open the form in view mode. Doesn't look too bad now, does it? In fact, it looks quite professional. This was very easy to do by just using the wizard and then fixing the positions of a few controls.

Figure 25 - Click here to view a larger version of the image.

Step Number 26

Now, close the form and save your changes.

Figure 26 - Click here to view a larger version of the image.