Creating Forms

Return to Tutorial homepage

Simple Forms | Forms drawing data from more than one table

Simple Forms

  1. From the Database Window, select the “Forms” tab.
  2. Click on “New
  3. I usually prefer to let the Access wizard create a basic form for me.  Then I can modify it as I please. So, choose the Form Wizard.  Also, pick the table whose contents we wish to display in the form (CD, in this case).

    Figure 1: Choosing the Source of Data for a new Form

    Click OK to go to the next screen.
  4. Access will lead you through dialog boxes that ask you:

    To choose the fields you'd like on the from, click on a field in the the left-hand column, then on the arrow to move that field into the right-hand column:

    Figure 2: Choosing fields to put on a form.

    When you've chosen the fields you want on the form, click Next>

  5. The Form Wizard will then ask you to choose a basic layout for your fields.  In this tutorial, stick with Columnar, but feel free to take a look at the others as well.

    Figure 3: Choosing the Form layout.

    Click Next when you are ready to move on.
  6. The Style of a Form refers to the background pattern, the color and font of labels, etc.  Access has a number of standard styles to choose from.   Here we've chosen SandStone, for no particular reason.

    Figure 4: Choosing the Form style.

    Click on Next to continue.
  7. Finally, provide a title for your Form, which will show up both in the title bar and on the form.   At this point you may see the completed form, or choose to modify it further before opening it.

    Figure 5: Providing a Title for your form.

    Click on Finish.
  8. Once you’ve created a form (say, using the wizard), you are free to alter it. Clicking on controls will select the control.  The selected control will have black boxes (handles) around the edge:

    Figure 6: Selecting controls on a form.

    Double-clicking on a selected control will show you the properties of that control (another way to see the properties is to select the control, and then choose “Properties” from the “View” menu). You can change things like the color, the borders, and many, many other properties. Experiment.

    Figure 7: Control properties.

  9. There are a number of ways you can look at a form:  in Design View (where you can make changes), in Form View (where you see what the form will look like to the user) and in Datasheet View (where the form looks like a table).  Choose your view from either the View menu, or by clicking on the icon that looks like this:

    Figure 8: Form views
  10. To add additional controls onto the form, use the toolbox, shown to your right.
    1. If you want to create a control that asks the user to select from a list of items rather than type in a (possibly incorrect) entry, use a combo box or a list box.  Be sure the wizard is activated.  It will make life a lot easier.  The wizard will guide through the choices you need to make.  If you've created a list or combo box to replace an existing control (field) on the form, you will have to delete the old control.  On the form, the combo box control looks like this:

      Figure 9: Combo boxes.
    2. If you wish for more information on adding controls, see some examples.
  11. If you want to add a control to the form that is based on some field in the underlying table (e.g. a text box), it is best to: a) bring up the field list (it’s in the “View” menu)

    Figure 10: The Field list.

    and b) drag and drop the field you want onto the form.

    Figure 11: Adding a field to a form from the field list.

Forms with data from more than one table.

A very common type of form is one that displays so-called "Master-detail" data.  Every day examples of such displays include your telephone bill, your credit card statement, the list of classes you are taking, etc.  The common characteristic of such arrangements of data is that for each "thing"  (master record) there are multiple associated detail records.  For example, on your telephone bill, some of the displayed data describes the customer who received the bill (Name, Account number, Telephone number, Address, etc.) and appears once.   The details of telephone calls appears on the form as multiple rows with similar format.  Each row shows the Date of a call, the City called, the Duration of the call, the Time of day, etc.  

The master and the detail data are likely to be stored in separate tables in Relational databases.   These tables will have what is known as a one-to-many relationship.   One customer has many telephone calls, but each telephone call is billed to only one customer.  In this tutorial, one CD is associated with many tracks, while each track is associated with one CD.

Because such master-detail arrangements of data are so common, and because in databases the master data and the detail data are likely to be stored in separate tables, Microsoft has developed an easy way to create a single form to display data both the master and the detail data.

We will create what Access calls a Main Form/Subform construct.  A Main Form will display data from the table that is the one part of the one-to-many relationship (i.e. from CD), while a Subform will display data from the table that is the many part of the one-to-many relationship (from Tracks).  The Subform will be planted on the Main Form.

  1. In the Database Window, click on the “Forms” tab.
  2. Click on the “New” button.
  3. Choose the "Form Wizard" option and select the table that will provide data for the Master portion of the form (CD, in this case):

    Figure 12: Creating a new form.

    Click OK.
  4. In the next dialog box, select the columns of master data you wish to see on your form:

    Figure 13: Choosing fields for a form.

    At this point, we are proceeded exactly as before, when creating a form based on a single table.
  5. To include columns as well from the detail table (Tracks), choose the Tracks table from the combo box on this same dialog box.  Do not click Next yet.

    Figure 14: Choosing fields from a second table for a subform.

    In the screen-shot above, I have selected the Tracks table, seen the list of available fields from the Tracks table, and chosen two of them (Track_No, Track_Title) to be included on my master-detail form.
    Now, click Next >
  6. Access now asks you to confirm the layout of the data from the two underlying tables.  

    Figure 15: Choosing subform style for the main/subform.

    Choosing the Form with subform(s) option makes all of the fields you've chosen visible at the same time on the same form.  Choosing the Linked forms option creates a button on the main form which, when clicked, will bring up a second form with the associated detail records.  
    Click Next >
  7. A further decision you must make is how you wish the detail data columns to appear.  Datasheet makes them appear in a single table.  Tabular gives each data element its own textbox on the form.

    Figure 16: Choosing a layout for the main/subform.

    Click Next >
  8. As for the form based on a single table, you are then asked to choose a background style, provide a title for your form and for the subform containing the detail data, and whether you want to view the form directly or modify its design.  The end product appears below:

    Figure 17: The main/subform.

Return to top

Previous Section:  Creating a database
Next Section: Creating queries