Creating Forms

Making data-entry and access to information easy

To display and enter data on a record-by-record basis using a customised page layout, you create forms. Forms are an easy way to view and edit only the information you want to see in your tables or queries in the way you like to see the information using special graphical items called controls for displaying information, on a record-by-record basis.

Forms are not absolutely necessary when creating a database. But if you want to make entering and modifying data in your database easier for other people, you will need to design forms with all the necessary colour and distinctive features you can muster and incorporate into your database (without overdoing it, of course!).

For example, instead of entering data into a table displaying all its fields like so,

It may be better to display only the fields you want to see in a form and edit their data like so,

This gives us an idea of what forms are all about in Microsoft Access.

How are forms created?

To build a form, you need to base your form on a table or query in your database. Once you know the table or query you will use for your form:

  1. Click the New button
  2. Microsoft Access provides you with three options: AutoForm Wizard, Form Wizard, or build a form from scratch yourself. First select the table or query you want the form to be based on from the popup list box and choose the option for creating the form.
  3. Click OK.
  4. If using the Form Wizard for creating a form, you will be asked to select the fields you want. Choose your fields and click the Next button. You will also be asked how Microsoft Access should present your fields: (i) Columnar (displays fields in a record in one column); (ii) Tabular (displays a list of records with fields running along a row); (iii) Datasheet (displays fields and their values in the same way as in Datasheet View); and (iv) Justified (displays the values of records in paragraph fashion).
  5. You will eventually be presented with a form for you to add and/or modify controls such as fields, graphics, text and so on.

How do I customise the form?

To make the form look the way you want, you modify its design by adding, moving around, and changing the behaviour and look of various elements on the form known as controls. A control is a piece of text, a button, a graph, even a field from a table.

Examples of controls include the following:

1. A Text and a Number box:

2. A Combo box:

3. A List box:

4. A Check box:

5. Radio or Option buttons:

6. Text box:

7. Command button:

8. Subform:

How do I add a control to a form?

To add a control to a form, you use the toolbox that should appear in your form in design view. If the toolbox is missing, click the Toolbox button on the toolbar.

Click a tool in the toolbox and click where you want to place that chosen control type in your form.

How is it that whenever I enter data into the text box, the table data is not updated?

There is one important thing you need to remember when creating forms in Microsoft Access. If you have chosen a text box from the toolbox as a control, it will appear on the form as an unbound text box. An unbound text box simply means that the control is unlinked (or unassociated) to a field in the underlying table or query. To make the text box linked, and thus bounded, to a field in the table or query:

  1. Click the Text Box tool in the toolbox.
  2. You will be shown a list of fields available for your form. Click the field you want to bind to the text box and keep holding down the mouse button.
  3. Now drag the field to the upper-left corner of the text box on the form and release the mouse button. Your text box is now bound to that field and creates a label for the text box (unless you have set the default otherwise).

OR

  1. Click the control to select it. Remember, select the control and not its label!
  2. Click again within the control. An I-beam cursor appears inside the control.
  3. Type the name of the field exactly as it appears in the table or query underlying the form.
  4. Press Return. The text box is binded to the field.

OR

  1. Click the Field List button on the toolbar to show all of the fields in the table or query bound to the form you are designing.
  2. If the Field List button is disabled, it means you have not binded your form to a table or query. Click the Properties button on the toolbar and from the Edit menu, choose Select Form. Select a table or query from the property sheet and then click the Field List button on the toolbar to open the field list.

NOTE: You can also create a special text box known as a calculated field whereby it displays a calculated value in your form. Just click the control to select it (but not its label!), and click again within the control. An I-beam appears. Now type an expression that can calculate values for the control. You may use existing data in a table or query by typing the name of the field inside square brackets ([....]) if required. Press the Return key when finished.

Can I remove a control?

To remove or delete a control:

  1. Click on the control you want to delete.
  2. Press the Del key, or choose Delete from the Edit menu.

How do I move a control?

  1. Click the control to select it.
  2. Move the mouse pointer to the edge of the control until the pointer changes to an open hand (meaning the control and its label is ready to be moved), or a pointing finger (meaning the control selected will be moved only).
  3. Open hand.

    Pointing hand.

  4. Now click and drag the control where you want it and then release the mouse button.

NOTE: Press Ctrl button and the arrow keys to move the control on a pixel-by-pixel basis.

How do I align controls, adjust the space between them, and make the controls appear in front or behind another control?

To align controls and making the vertical and/or horizontal spacing between the controls even, you can:

  1. Select the controls. Press the Shift button while clicking on the controls with your mouse button to select them all.
  2. To align the controls, choose Align from the Format menu.
  3. Choose either Left, Right, Top or Bottom from the Align submenu to align the controls appropriately.
  4. To adjust spacing between controls, choose Horizontal Spacing or Vertical Spacing from the Format menu.
  5. Choose the appropriate spacing adjustment you want from the submenu.
  6. To send controls to the back or front, select your control and choose Bring to Front or Send to Back from the Format menu.

What else can I do with my controls?

There are many more things you can do with your controls. For example, you may want (i) to add a picture to a button control (a Picture property); (ii) to prevent a user from editing the data in a bounded text box (a Locked property); (iii) to display data in a bounded text box in a certain format (an InputMask property); (iv) to set a default value to a bounded text box (a DefaultValue property); (v) to add validation properties to a control (a Validation Rule property); (vi) to allow data entry on a form whenever you want to add new records while preventing existing records from being edited (a DefaultEditing property); and/or (vii) to check the validity of data using a set of recorded actions called a macro (a BeforeUpdate property).

All this can be achieved by selecting the appropriate control(s), clicking the Properties button on the toolbar, and then changing the properties of the control within the property sheet (or, in some cases, via the Edit menu command).

Go ahead and experiment with these options. You might be surprised at what you can achieve. For further information about various properties for a control, use the Microsoft Access help files.

What about my text controls? Can they be formatted in a different way?

All text controls (eg labels, bounded text boxes etc) can have their font, font size, text style, text alignment, and other aspects of your text changed to suit your designing needs. Click the text control you want, and use the text tools available on the toolbar to modify the appearance of your text just like a word processor.

Can I resize my controls?

To resize your controls:

  1. Click the control to select it.
  2. Move the mouse pointer to one of the sizing handles (appearing as solid square dots on the edge of the control) until the pointer becomes a double-headed arrow.
  3. Double-clicking on the sizing handle will automatically resize the control to fit its current contents. Or click on the handle and while holding down the mouse button, drag the handle until you are happy with the size of your control and let go of the mouse button.

Can I include a header and footer section in my form just like a Word document?

Yes, but these are optional features. If you want to include them in your form, go to the Format menu and choose Page Header/Footer or Form Header/Footer to add or delete the form's header and footer. Remember, if you delete a header and footer section in your form, you will permanently delete any control that lies inside the header or footer area (even if most of the control lies within the main body section of your form).

Once you've added a header and footer section to your form, it then becomes a matter of resizing the height of each section to suit your needs. To change the section height:

  1. Move the mouse pointer over the line dividing the header or footer section from the main body section. The pointer changes to a double-headed arrow with a solid line through it.
  2. Click on the line and while holding down the mouse button, drag the line to where you want it.
  3. Release the mouse button.

What are headers and footers?

In case you are not aware of the purpose behind header and footer sections in a form, placing controls in a Page Header or Page Footer will ensure they are printed on every page. Form Headers and Form Footers do a similar job, except the controls are printed once (i.e. the first record only).

Use Form Headers and Footers for controls where you don't want to repeat the same information record-by-record such as the title and date of the form. Or use these sections them to keep certain Command buttons in the same position on the screen for a variety of different forms you create.

How do I add a form within a form?

Now you are getting into an interesting area of form design. A form inserted into another form is termed a subform. You probably want to add a subform because the form's underlying table or query has a relationship with another table or query and you want to view and/or edit the data in this other table or query on the form itself.

To make a subform, you need to have designed a second form containing the fields of the second table or query, ready for inserting into your first form. If you have the second form ready:

  1. Click the Database Window button on the toolbar to switch to the Database window, and make sure you are looking at your forms by clicking the Form Object button.
  2. To perform the next tricky operation, choose Tile from the Windows menu. This makes it easy to view the Database window and your form at the same time.
  3. Make sure you are still in the Database window with the Form button selected.
  4. Now click the name of the form you want to insert into your main form, which is currently in design view. The form you have selected as your subform should be bound to the table that has the "many" side of the one-to-many relationship. Your main form should therefore be the "one" side of the one-to-many relationship.
  5. While holding down the mouse button, drag this form into the main form and release the mouse button. Microsoft Access inserts the form as a subform within the main form.

NOTE: To change the appearance of your subform: (i) Open the subform in design view and click the Properties button; (ii) Click the Format tab in the Properties sheet and change the value in the Default View property; and (iii) Save your form. You should now open the main form containing your subform to see what it looks like.

How do I check for errors in my form?

In Microsoft Access 2003, a new feature has been added to check and highlight errors in your forms (and reports). This is useful when you want to know whether a text box is unassociated with a field in an underlying table or query, a label is not associated with a control, controls outside the page size, invalid control properties, or keyboard shortcut errors.

To activate this feature and click the Error Checking Options button when it appears for errors it finds, choose Tools>Options in the menu command. Click the Error Checking tab, and place a tick in the box that says "Enable error checking". Choose and error indicator colour and design rules you wish to follow and have Microsoft Access check for you.

How do I save the design of a form?

Once you have twiddled around with the form and turned it into a masterpiece, save the design of the form by:

  1. Click the Save button on the toolbar.
  2. If you have not given a name for your form, you will be prompted for one. Type the name of your form when asked and then click OK.

If you have finished with the form, choose Close from the File menu to get you back to the main Database window.

And that's the essence of form design using Microsoft Access!