Section 12.3. Creating Better Layouts


12.3. Creating Better Layouts

So far, all the forms you've been creating look fairly similar: All the fields get channeled into one or more columns of tightly packed information. In many cases, that system works perfectly fine. But sometimes you want to let your inner form designer come out and play.

You've already seen this idea with reports in Chapter 11. Once you break a report out of its layout table, you can create a printout that looks more like a retail product catalog than a drab table of information. The same principle's at work with formsonce you decide to leave the Simple World of Simple Forms, you can create forms that are a lot more original. You can create forms that use white space to break up dense groupings of information; forms that add graphical frills like pictures, lines, and rectangles; forms that pack information more tightly or more loosely; forms that resemble the paper documents they're based on; and so on.

12.3.1. Liberating Controls from Layouts

Like reports, forms use a helpful feature called a layout : a formatting container that Access uses behind the scenes to arrange a group of controls. If you widen one field in a layout, all the other fields in it are widened as well. If you move a layout, all the controls move along with it. And if you rearrange a layout, all the controls maintain a consistent amount of spacing.


Note: Remember, controls (Section 11.1.2) are the ingredients you can add to a form or report. Controls include things like labels, pictures, and text boxes. You use some controls to display fixed content (like your form title), while others have dynamic content (like the field values from the current record).

If you want to be able to arrange your controls precisely, then you need to start by removing them from the layout. (And, as with reports, it takes a fair amount of time to place each control by hand and still make sure things looks nice.)

Before you pull a control out of its layout, make sure you're in Layout view or Design view (by right-clicking the tab title, and then choosing Layout View or Design View). Layout view's a bit nicer to look at, but Design view makes it a bit easier to move your fields. When you drag a field caption (like the label that contains the word "ProductName") in Design view, the linked control that shows the field value moves along with it. In Layout view, you need to move both pieces separately, which makes for twice as much work. (Incidentally, you can drag the captions and field boxes separately in Design view too, if you understand where to click. Section 11.1.5 explains.)

To actually remove a field, right-click the field you want to reposition, and then choose Layout Remove. Finally, drag the field to its new location. Figure 12-12 shows an example of aform that doesnt use layouts for any of its controls.

Figure 12-12. The weird staggered effect shown here wouldn't be possible with the rigid table-based structure of a layout. But you pay a price for this design (and it's not just eye strain). If you ever modify the table and need to update the form, then you'll have more work to rearrange the fields, since there's no layout behind the scenes holding them all together.


12.3.2. Using More Than One Layout

As you learned earlier in this chapter, Access arranges fields into more than one column if it can't fit them all in just one (as shown in Figure 12-2). When Access creates multiple columns, each column's actually a separate layout.

Great news: You too can create multiple layouts. You might want to for several reasons, including:

  • To arrange your fields in side-by-side columns . You do this by placing one lay-out next to another.

  • To arrange your fields into several discrete groups . These fields can appear in different places on the form. You could have one group at the top and one group at the bottom, separated by other content.

  • To give different width to different fields . All the fields in a layout have the same width. If you place your fields into different layouts, they can have different widths.

To place fields into a new layout, follow these steps:

  1. Make sure you're in Layout view .

    If not, right-click the form's tab title, and then choose Layout View.

  2. Right-click the first field you want to remove, and then choose Layout Remove .

    If the field's inside the middle of a layout table, Access pops it off to the side. If the field's at the end of the layout table, its position doesn't change.

  3. Drag your field off to another part of the form .

    If you want to place your second layout beneath the first, then drag this field down the form to its new position.

  4. Right-click the field you've removed, and then choose Layout Stacked .

    This action creates a new layout for the field you cut loose in step 2.

    All the layouts you've seen so far are stacked, which means the fields appear one on top of the other. You'll see an example of tabular (side-by-side) layout in the next section.

  5. Find one of the fields you want to move into the new layout, and then drag it down there (Figure 12-13) .

    Dragging a field from one layout to another's a shortcut. It's faster than removing all the fields you want from the first layout, and then adding them to the second layout.

    Figure 12-13. As your mouse cursor passes over the new layout you've just created, a yellow line appears showing where the field will be placed if you release the mouse button. You can drop a field at the top of the layout, at the bottom, or anywhere inside. In this example, the PostalCode field's being placed between the State and Country fields.


  6. Repeat step 5 for each of the fields you want in the new layout .

    Moving fields between layouts can be a bit tricky. If everything goes wonky and a field lands in the wrong place, then just use the Undo feature to put things right. (Undo an action by pressing Ctrl+Z, or by clicking the Undo button in the Quick Access toolbar above the ribbon.)

  7. When you've perfected your second layout, move it to the correct position .

    To move your layout, click one of the fields and then look for the four-way-arrow icon in the top-left corner. Drag that icon to move the whole layout. Be carefulif you place a layout too close to another layout, then Access assumes you want to merge them into a single layout. (You can hold down the Ctrl key while you drag to tell Access not to do this.)

    Figure 12-14 shows a finished form with several layouts.

12.3.3. Using Tabular Layouts

Layouts can organize controls in two different ways: in stacked groups (where each field's in a separate row) and in tables (where each field's placed in a separate column). Usually, stacked group layouts are more useful for forms, while tabular lay-outs make sense for densely packed reports. However, you may occasionally choose to use a tabular layout in a form. You'd do this most often when you want to show more than one record at a time; it's often easier to fit more onscreen when you pack fields into columns.


Tip: Although a form can contain several of both types of layout (tabular and stacked), they rarely fit well together. So pick one and stick with it.

To change an ordinary form (with a stacked layout) so that it uses a tabular layout, follow these steps:

  1. Make sure you're in Layout view .

    If not, right-click the tab title, and then choose Layout View.

    Figure 12-14. This form groups fields into four neat subsections. It adds a clearer, more structured organization than a single layout table but dodges the complexity of creating a form without any layouts, especially if you need to add more fields or change their order later on.


  2. Select all the fields on your form by holding down Shift and clicking them one at a time .

    To save some time, look for the four-way-arrow icon that appears at a layout's top-right corner when you select something inside it. You can click this icon to select the whole layout in one shot.

  3. Right-click your selection, and then choose Layout Tabular .

    When creating a tabular layout, Access puts each field caption in the form's header area and the corresponding field value underneath, as shown in Figure 12-15. You'll need to perform some drag-and-drop fiddling to get all the fields in the right order, and to make them the right sizes.

This process is a bit awkward . Fortunately, there's a shortcut. If you know you want to use a tabular layout, then you can create one from the beginning. Instead of choosing Create Forms Form to create your form, choose Create Forms Multiple Items. Doing so creates a form that uses a tabular layout and shows more than one record at a time (Figure 12-16).

Figure 12-15. This tabular layout shows four columns of information. This form's got one layout-less control: the box for the Notes field, which the person designing this form has moved down to make room.


Figure 12-16. Usually, tabular layouts go hand-in-hand with forms that show lots of records at once, like the form shown here.


12.3.4. Showing Multiple Records in any Form

You can show more than one record in a form even if you don't use a tabular layout. In fact, as long as your form's fairly compact, it's easy. Here's how:

  1. Arrange your form so that it's as compact as possible .

    When showing multiple records, they're placed one above the other, as shown in Figure 12-17. So the shorter you make your form, the more records you can see at once. On the other hand, it doesn't matter how wide or narrow your form is (so long as everything fits on your screen at once).

    Figure 12-17. Now you can see three products all on the same screen. (Notice how the bottom three fields have been removed from the top three fields' stacked layout so they can fit more tightly together.) The arrow in the margin indicates that the second record's the current record. To see more records, you can use the familiar record navigation buttons at the bottom of the form, or you can use the scroll bar on the right.


  2. Switch to Design view, if you're not there already .

    As always, you can switch to Design view by right-clicking the tab title and then choosing Design View.

  3. Resize your form so there's no blank space, as shown in Figure 12-18 .

    As you rearrange your controls, you'll free up space at the bottom of your form. However, it's up to you to reclaim this space by shrinking the overall form. If you try to shrink a form but it remains stubbornly locked in place, there's probably a control on the form that extends into that space. You need to shrink the control first and then the form.

    Figure 12-18. To shrink the form, drag the bottom border up, until it reaches the bottom of the lowest control.



    Note: In order to fit more than one record into view at once, the form window needs to be larger than the actual form.
  4. If the Property Sheet isn't visible, then choose Form Design Tools Design Tools Property Sheet .

    As you learned in Chapter 11, the Property Sheet lets you tweak the settings for controls and other items. In this case, the setting you need to change isn't available in the ribbon. Instead, it's buried in the Property Sheet.

  5. In the Property Sheet list box, choose Form .

    This action shows settings that apply to the entire form, not just a single control.

  6. Click the Format tab, and then find the Default View setting .

    The Default View setting appears near the top of the list. It lets you control how the form appears when you first open it.

  7. Choose Continuous Form .

    The most common options are Single Form (which shows a single record of information), and Continuous Form (which shows multiple records, one after the other). You can also choose a non-Form view, like Datasheet (the boring spreadsheet-like tables you learned about in Chapter 3), PivotTable, or Pivot-Chart. Finally, you can use Split Form for a view that combines the datasheet with your custom form. You'll learn more about this option in the next section.

  8. Optionally, set the Dividing Lines property to Yes to show a thin horizontal line between each record .

    Now, when you switch back to Form view, you'll see several records at once, provided they fit into the window.

12.3.5. Split Forms

Both single-record view and multiple-record view have their advantages. With single-record view, you have plenty of room to examine one record, and you don't get distracted by onscreen clutter. With multiple-record view, you can compare the current record to other nearby records.

Access has a type of form that lets you get the best of both worlds : split forms . Split forms combine two views of your data in one form. The idea's that you can use the datasheet to scroll through all your records, and use the form to view or edit a recordbut all in the same window. Figure 12-19 shows an example.


Note: Usually, you'll use the datasheet to move to the record you want to edit and the form to review or edit it, but that way's not necessaryyou can change records in the datasheet, and you can navigate using the navigation buttons at the bottom of the form.

Figure 12-19. The most common type of split form puts the datasheet section at the top. The currently selected record's shown underneath. You can change the size of each portion by dragging the splitter bar that's in between.


It's easy to create a split formall you need to do is, on the ribbon, choose Create Forms Split Form. However, you need to know a little bit more if you want to convert an existing form into a split form, or if you want to change how Access presents the two sections of a split form.

The secret lies in changing the form settings using the Property Sheet. Here's how:

  1. Switch your form to Design view .

  2. If the Property Sheet isn't already visible, then show it by choosing Form Design Tools Design Tools Property Sheet .

  3. Choose the Format tab, which includes all the settings that relate to split forms .

  4. Find the Default View, and then set this to Split Form. Now you get the two-part window shown in Figure 12-19 .

Several more settings let you control how split forms work. Table 12-1 has the details.

Table 12-1. Form Properties for Split Forms

Property

Description

Split Form Orientation

Using this setting, you can place the datasheet portion of the window at the top (the standard choice), at the bottom, on the left, or on the right.

Split Form Size

Sets how large the datasheet portion of the window appears. You'll need to experiment with different numbers to find what works. Most people prefer to size the split window by hand in Form view.

Split Form Splitter Bar

If you change this setting to No, there won't be a splitter bar in between the two portions of the window. You (or the person using the form) can't change the space allocated to each portion by dragging the splitter bar. Instead, you'll be stuck with the size that's specified in the Split Form Size setting.

Save Splitter Bar Position

If you change this setting to Yes, every time you move the splitter bar, the datasheet size is recorded in the Split Form Size setting. The next time you open the form, the splitter bar's positioned where it was most recently. If you change this setting to No, then Access doesn't save your changes. The splitter bar reverts to its original position, as set in the Split Form Size property.

Split Form Datasheet

Change this setting to Read Only if you want to prevent people from changing data in the datasheet section of the window. (They can still use the datasheet to navigate from one record to another.) Doing so's one way to prevent errors caused by accidental key presses. If you want to prevent edits altogether, then use the Allow Edits, Allow Deletions, and Allow Additions settings described in Table 12-2.

Split Form Printing

Tells Access whether to use the datasheet view (Datasheet Only) or the Form view (Form Only) to create a printout. The standard setting's Form Only, which means Access organizes the information in your printout to fit your form's layout.


12.3.6. Even More Useful Form Properties

So far, you've used the Property Sheet to change the view of your form, letting an ordinary form show multiple items or a split view. However, the Property Sheet's packed with many more settings. Some are useful; others you'll almost never touch. Table 12-2 lists a few more settings that may come in handy.

Table 12-2. Useful Form Properties

Property

Tab

Description

Record Source

Data

Where the data comes from. This property's usually the name of a table or query in the database. However, if you're technically inclined, then you can type a new SQL command (Section 6.2.3) directly into this field.

Filter

Data

The filter expression that's used to limit results. You can set this field by hand, or build a filter expression using the ribbon, as described in Section 12.2.2.

Filter On Load

Data

If set to Yes, the filter expression's applied as soon as you open the form. If No, the filter expression's stored, but not applied until you choose Home Sort & Filter Apply Filter.

Order By

Data

The sorting expression you use to order results. You can set this field by hand, or set the sort order using the ribbon, as described in Section 12.2.

Order By On Load

Data

If set to Yes, Access applies the sort order as soon as you open the form. If No, the sort order's stored but not applied. That option's not particularly usefulunless you open up the Property Sheet again and set Order By On Load back to Yes, the stored sort order won't ever come into effect.

Allow Filters

Data

If set to No, you can't use any of the filtering commands described in this chapter. Instead, you'll always see all the records.

Caption

Format

The text that appears in the tab title (or the window caption, if you're using overlapping windows instead of tabbed documents). If you leave this blank, then Access uses the form's name as the caption.

Allow [ ] View

Format

These settings let you turn off a particular view. For example, if you set Allow Layout View to No, you don't see the option for switching your form to Layout view.

Allow Edits

Data

If set to No, you can't change any data in the form. However, you can still add a new record with all-new data. The standard option's Yes.

Allow Deletions

Data

If set to No, you can't delete any record while using this form. The standard option's Yes.

Allow Additions

Data

If set to No, you can't insert a new record with this form. The standard option's Yes.

Data Entry

Data

If set to Yes, this form can only be used to add new records. When you switch to Form view, you don't see any of the existing records. Instead, you see a blank slate where you can add a new record. As you add new records, they remain visibleat least until you close the form and reopen it.

Record Selectors

Format

If set to No, your form doesn't include the margin on the left. This margin has two roles. First, it shows an arrow next to the current record (which is useful in forms that show several records at a time). Second, if you click the margin, then you can select the entire record (after which you can quickly delete it with the Delete key).

Navigation Buttons

Format

If set to No, your form doesn't include the handy navigation controls at the bottom that let you jump from record to record. You're most likely to use this option if you're designing a form with a radically different appearance and you don't want any of the Access staples , or if you're creating your own navigation buttons that use VBA code.



Note: Many form properties apply only in the rare case that you're using free-floating windows (Section 1.3.6). You can choose whether the window's automatically centered (Auto Center), whether it can be resized (Border Style), whether it includes minimize and maximize icons (Min Max Buttons), and so on. These properties have no effect if your database is using the more standard tabbed windows.
UP TO SPEED
The Access Form Family

Access forms manage to please just about everyone. If you're in a hurry, then you can create a ready-made form with a basic layout and add a dash of formatting. Or, if you're feeling a creative buzz coming on, you can pull your fields out of the standard layouts and place them absolutely anywhere. In other words, forms are flexibletime-pressed business types get the convenience they need, while serious artistes get the creative control they demand.

Here's a roundup of all your form choices:

  • A simple form shows one record at a time in a basic stacked layout. To create a simple form, choose Create Forms Form.

  • A layout-less form lets you place controls anywhere you want on a form. It's up to you whether you want to show a single record at once, or several records at a time. When creating a layout-less form, you need to do all the work. You can get started by choosing Create Forms Form Design (to start in Design view) or Create Forms Blank Form (which starts you in Layout view).

  • A tabular form shows records in a tabular layout. Usually, tabular forms show several records at once (which gives the appearance of a table). To quickly create one of these babies, choose Create Forms Multiple Items.

  • A PivotChart or PivotTable form is a form that exists for the sole purpose of showing a PivotChart or PivotTable (see Chapter 9). You can create these forms by choosing Create Forms PivotChart and Create Forms More Forms PivotTable. Section 9.3 has more.

  • A datasheet form looks exactly like the Datasheet view you get with a table. This form's not as powerful as other form types, but it's still useful if you want a customized datasheet-like view of your data. You can create a datasheet form that shows fewer columns, uses filtering to hide certain records, prevents record insertions, uses different formatting, and so on. To create a datasheet form, choose Create Forms More Forms Datasheet.

  • A split form combines two types of form in one window. One portion of the window shows the current record in a simple form. The other portion of the window shows a datasheet with several records. To create a split form, choose Create Forms Split Form.

  • A modal dialog is a special type of form. Rather than show data from a table, the modal dialog asks you a question. The idea's that you can pop it up at some critical moment as part of an automated task. To use modal forms, you'll need to mix in some VBA code. You'll see an example that uses a modal form (also known as a dialog form) in Section 17.4.3.




Access 2007[c] The Missing Manual
Access 2007[c] The Missing Manual
ISBN: 596527608
EAN: N/A
Year: 2007
Pages: 153

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net