[ Team LiB ] Previous Section Next Section

Working with the Form Design Window

You use the Form Design window to build and customize a form. Using this window, you can add objects to a form and customize them by using the many properties available in the Properties window. Microsoft has supplied many form and control properties. After gaining a command of these properties, you can customize the look and feel of your forms.

Understanding and Working with the Form Design Tools

A developer needs the right tools for the job. Fortunately, Microsoft provides tools that help you build exciting and utilitarian forms. The Form Design window includes a toolbar, a toolbox, and the actual form you're designing. Other tools are available to help you with the design process, including the Field List and Properties windows.

By default, two toolbars appear when you're in a form's Design view: the Form Design toolbar and the Formatting toolbar. The Form Design toolbar has buttons you use to save, print, copy, cut, paste, and perform other standard Windows tasks within a form. It also includes buttons that allow you to toggle the different design windows (such as the toolbox). Additional tools in the Form Design toolbar include the Format Painter tool and the Build tool. The Format Painter tool allows you to copy all formatting from one control to one or more additional controls. You can use the Build tool to open the Choose Builder dialog box, where you can invoke the Expression, Macro, and Code builders. The Formatting toolbar contains tools for graphically modifying a form's properties and objects. You can modify the font, font size, and color of selected objects on the form. With the Formatting toolbar, you can also add bold, underline, and italic; change the alignment; and add special effects to the selected objects.

Toggling the Tools to Get What You Want

Many windows are available to help you with the design process when you're in a form's Design view. If you don't have a high-resolution monitor (1,024x768), you'll probably find it annoying to have all the windows open at once. In fact, with all the windows open at once on a low-resolution monitor, a form is likely to get buried underneath all the windows. This is why Microsoft has made each window open and close in a toggle-switch–like fashion. The Form Design toolbar has tools for the Field List, Toolbox, and Properties windows, and each of these toolbar buttons is a toggle. Clicking once on the button opens the appropriate window; clicking a second time closes it.

Figure 11.3 shows a form with the Field List, Toolbox, and Properties windows open. Although you can size each of these windows however you like (and you can dock the toolbox to a window edge), the design environment in this low-resolution display is rather cluttered with all these windows open. One of the tricks in working with Access is to know when it's appropriate to have each set of tools available. The goal is to have the right windows open at the right time as often as possible.

Figure 11.3. The Form Design toolbar with Design windows visible.

graphics/11fig03.jpg

graphics/bulb_icon.gif

You can close the Field List, Toolbox, and Properties windows by using the toolbar buttons. In addition, you can close them by using the Close button on each window, or you can toggle them by using the View menu.


graphics/bulb_icon.gif

Access 2002 and Access 2003 offer some handy shortcut keystrokes for working with forms and form properties. In Design view, the F4 key displays the property sheet. When you're working with a property sheet in Design view, pressing Shift+F7 shifts the focus to the Form Design window while maintaining the focus on the selected control. You can toggle among all available views for a form (that is, Design, Datasheet, Form, PivotTable, and PivotChart) by pressing Ctrl+> or Ctrl+. (period). You can toggle among the different views in the reverse order using Ctrl+< or Ctrl+, (comma). Access also supports these shortcut keys for toggling between the views that are available for tables, queries, reports, pages, views, and stored procedures.


Adding Fields to a Form

graphics/newterm_icon.gif

You can use the Field List window to easily add fields to a form. The Field List window contains all the fields that are part of the form's record source. The record source for a form is the table, query, or embedded Structured Query Language (SQL) statement that produces the data for the form. For example, in Figure 11.4, the form's record source is the Customers table. The fields listed in the Field List window are the fields that make up the Customers table. To add fields to a form, follow these two steps:

  1. Make sure the Field List window is visible. If it isn't, click the Field List button on the toolbar.

  2. Locate the field you want to add to the form; then click and drag the field from the field list to the place on the form where you want it to appear. The location you select becomes the upper-left corner of the text box, and the attached label appears to the left of where you dropped the control.

Figure 11.4. A form based on the Customers table.

graphics/11fig04.jpg

graphics/newterm_icon.gif

A control is an object that you add to a form or report. Types of controls include text boxes, combo boxes, list boxes, and check boxes.

To add multiple fields to a form at the same time, follow these steps:

  1. Select several fields from the field list.

  2. Hold down the Ctrl key to select noncontiguous (not together) fields or the Shift key to select contiguous (together) fields. For example, if you hold down the Ctrl key and click three noncontiguous fields, each of these three fields is selected. If you click a field, hold down the Shift key, and click another field, all fields between the two selected fields are selected. If you want to select all the fields in a list, you double-click the field list title bar and then click and drag any one of the selected fields to the form; all the fields are then added to the form at once.

Selecting, Moving, Aligning, and Sizing Form Objects

You must know several important tricks of the trade for selecting, moving, aligning, and sizing form objects. These tips will save you hours of frustration and wasted time.

Selecting Form Objects

The easiest way to select a single object on a form is to click it. After you have selected the object, you can move it, size it, or change any of its properties. Selecting multiple objects is a bit trickier, but you can accomplish it in several ways. Different methods are more efficient in different situations.

It's important to understand which objects you've actually selected. Figure 11.5 shows a form with four selected objects. The CustomerID text box, the Company Name label, and the Address label and Address text box are all selected; however, the Customer ID label and CompanyName text box aren't selected. If you look closely at the figure, you can see that the selected objects are completely surrounded by selection handles. The Customer ID label and CompanyName text box each has just a single selection handle because each is attached to an object that is selected. If you changed any properties of the selected objects, the Customer ID label and CompanyName text box would be unaffected.

Figure 11.5. Selecting objects on a form.

graphics/11fig05.jpg

One way to select multiple objects is to hold down the Shift key and click each object you want to select. Access surrounds each selected object with selection handles, indicating that you have selected it.

You can also select objects by lassoing them. Objects to be lassoed must be adjacent to one another on the form. To lasso objects, you place the mouse pointer on a blank area of the form (that is, not over any objects) and then click and drag the mouse pointer around the objects you want to select. You can see a thin line around the objects the mouse pointer is encircling. When you let go of the mouse button, any objects that were within the lasso, including those only partially surrounded, are selected. If you want to deselect any of the selected objects to exclude them, you hold down the Shift key and click the object(s) you want to deselect.

One of my favorite ways to select multiple objects is to use the horizontal and vertical rulers that appear at the edges of the Form Design window. You click and drag within the ruler, and as you do this, two horizontal lines appear, indicating which objects are selected. As you click and drag across the horizontal ruler, two vertical lines appear, indicating the selection area. When you let go of the mouse button, any objects within the lines are selected. As with the process of lassoing, to remove any objects from the selection, you hold down the Shift key and click the object(s) you want to deselect.

graphics/bulb_icon.gif

You can use the Ctrl+A keystroke combination to select all controls on a form. After you have selected them, you can move them, size them, or change any of their other properties as a unit.


Moving Things Around

To move a single control with its attached label, you don't need to select it first. You place the mouse over the object and click and drag. An outline appears, indicating the object's new location. When the object reaches the position you want, you release the mouse. The attached label automatically moves with its corresponding control.

To move more than one object at a time, you must first select the objects you want to move. You select the objects by using one of the methods outlined in the previous section. When you place the mouse over any of the selected objects and click and drag, an outline appears, indicating the proposed new position for the objects. You release the mouse when you have reached the position you want for the objects.

Sometimes you want to move a control independently of its attached label, and this requires a special technique. If you click a control, such as a text box, as you move the mouse over the border of the control, a hand icon with five fingers pointing upward appears. If you click and drag, both the control and the attached label move as a unit, and the relationship between them is maintained. Figure 11.6 shows the label and text box before they've been moved as a unit. Figure 11.7 shows them after they've been moved as a unit. If you place the mouse pointer over the larger handle in the upper-left corner of the object, the mouse pointer appears as a hand with only the index finger pointing upward. If you click and drag here, the control moves independently of its attached label, and the relationship between the objects changes. Figure 11.8 depicts objects after they've been moved independently.

Figure 11.6. Objects before being moved.

graphics/11fig06.jpg

Figure 11.7. Objects after being moved as a unit.

graphics/11fig07.jpg

Figure 11.8. Objects after being moved independently.

graphics/11fig08.jpg

Aligning Objects to One Another

Access makes it easy to align objects. Figure 11.9 shows several objects that aren't aligned. Notice that the attached labels of three of the objects are selected. If you align the attached labels, the controls (in this case, text boxes) remain in their original positions. If you select the text boxes as well, the text boxes try to align with the attached labels. Because Access doesn't allow the objects to overlap, the text boxes end up immediately next to their attached labels. To left-align any objects (even objects of different types), you select the objects you want to align and then choose Format | Align | Left, or you can right-click one of the objects and select Align | Left. Access aligns the selected objects (see Figure 11.10). You can align the left, right, top, or bottom edges of any objects on a form.

Figure 11.9. A form before objects are aligned.

graphics/11fig09.gif

Figure 11.10. A form after objects are aligned.

graphics/11fig10.gif

graphics/book_icon.gif

You shouldn't confuse the Format | Align feature with the Align tools (that is, Align Left, Center, and Align Right) on the Formatting toolbar. Whereas the Format, Align feature aligns objects one to the other, the Align tools on the Formatting toolbar justify the text inside an object.


graphics/bulb_icon.gif

It is helpful to add to the toolbar the design tools that you commonly use. For example, you can easily add the Format | Align options to the toolbar. To modify the toolbar, you select Tools | Customize. Then you click to display the appropriate toolbar on the Toolbars tab. The alignment tools appear in the Form/Report Design category. You need to drag and drop the desired tools from the Commands list onto the appropriate toolbar.


Snap to Grid

The Snap to Grid feature determines whether objects snap to the gridlines on a form as you move and size them. This feature is found under the Format menu. If you turn off this feature (it's a toggle), you can move and size objects without regard for the gridlines.

graphics/bulb_icon.gif

I prefer to leave the Snap to Grid feature on at all times. You can use a special trick to temporarily deactivate the feature when needed: You hold down the Ctrl key as you click and drag to move objects, and Access ignores the Snap to Grid feature.


Sizing Controls

Just as there are several ways to move objects, there are several options for sizing objects. When you select an object, you can use each handle, except for the handle in the upper-left corner of the object, to size the object. The handles at the top and bottom of the object allow you to change the object's height, and the handles at the left and right of the object let you change the object's width. You can use the handles in the upper-right, lower-right, and lower-left corners of the object to change the width and height of the object simultaneously. To size an object, you place the mouse pointer over a sizing handle, click, and drag. You can select several objects and size them all at once. Each of the selected objects increases or decreases in size by the same percentage; their relative sizes stay intact. You use the upper-left handle to move an object independently of its attached label. This means, for example, that you can place the label associated with a text box above the text box rather than to its left.

Access offers several powerful methods of sizing multiple objects, which you access by selecting Format | Size:

  • To Fit— Sizes the selected objects to fit the text within them.

  • To Grid— Sizes the selected objects to the nearest gridlines.

  • To Tallest— Sizes the selected objects to the height of the tallest object in the selection.

  • To Shortest— Sizes the selected objects to the height of the shortest object in the selection.

  • To Widest— Sizes the selected objects to the width of the widest object in the selection.

  • To Narrowest— Sizes the selected objects to the width of the narrowest object in the selection.

Probably the most confusing of the options is Format | Size | To Fit. This option is somewhat deceiving because it doesn't perfectly size text boxes to the text within them. In today's world of proportional fonts, it isn't possible to perfectly size a text box to the largest possible entry it contains. Generally, however, you can visually size text boxes to a sensible height and width. You use a field's Size property to limit what's typed in the text box. If the entry is too large to fit in the allocated space, the user can scroll to view the additional text. As the following tip indicates, the Format | Size | To Fit option is much more appropriate for labels than it is for text boxes.

graphics/bulb_icon.gif

To quickly size a label to fit the text within it, you can select the label and then double-click any of its sizing handles, except the sizing handle in the upper-left corner of the label.


Controlling Object Spacing

Access provides excellent tools for spacing the objects on a form an equal distance from one another. Notice in Figure 11.11 that the CustomerID, CompanyName, Address, and City text boxes aren't equally spaced vertically from one another. To make the vertical distance between selected objects equal, you choose Format | Vertical Spacing | Make Equal. In Figure 11.12, you can see the result of using this command on the selected objects.

Figure 11.11. A form before vertical spacing is modified.

graphics/11fig11.jpg

Figure 11.12. A form after vertical spacing is modified.

graphics/11fig12.jpg

You can make the horizontal distance between objects equal by choosing Format | Horizontal Spacing | Make Equal. Other related commands that are useful are Format | Vertical Spacing | Increase (or Decrease) and Format | Horizontal Spacing | Increase (or Decrease). These commands maintain the relationships between objects while proportionally increasing or decreasing the distances between them.

Modifying Object Tab Order

Access bases the tab order for the objects on a form on the order in which you add the objects to the form. However, this order isn't necessarily appropriate for the user. You might need to modify the tab order of the objects on a form yourself. To do so, you select View | Tab Order to open the Tab Order dialog box, shown in Figure 11.13. This dialog box offers two options. First, you can click the Auto Order button to tell Access to set the tab order based on each object's location in a section on the form. Second, if you want to customize the order of the objects, you click and drag the gray buttons to the left of the object names listed under the Custom Order heading to specify the objects' tab order.

Figure 11.13. The Tab Order dialog box, where you select the tab order of the objects in each section of a form.

graphics/11fig13.jpg

graphics/book_icon.gif

You must set the tab order for the objects in each section of a form (that is, header, detail, and footer) separately. To do this, you select the appropriate section from the Tab Order dialog box and then set the order of the objects in the section. If the selected form doesn't have a header or footer, the Form Header and Form Footer sections are unavailable.


    [ Team LiB ] Previous Section Next Section