Training
Certifications
Books
Special Offers
Community




 
Microsoft® Office Access 2003 Inside Out
Author John L. Viescas
Pages 1344
Disk 1 Companion CD(s)
Level Int/Adv
Published 10/29/2003
ISBN 9780735615137
Price $49.99
To see this book's discounted price, select a reseller below.
 

More Information

About the Book
Table of Contents
Sample Chapter
Index
Related Series
Related Books
About the Author

Support: Book & CD

Rate this book
Barnes Noble Amazon Quantum Books

 


Chapter 12: Customizing a Form (continued)


Setting Form Properties

In addition to the controls on a form, the form itself has a number of properties that you can use to control its appearance and how it works.

Allowing Different Views

When you build a form from scratch (such as the employees form you’ve been working on in this chapter), the Default View property of the form is Single Form. This is the view you’ll see first when you open the form. With the Single Form setting, you can see only one record at a time and you have to use the Record Number box, the Previous Record and Next Record arrow buttons to the left and right of the Record Number box, or the Go To command on the Edit menu to move to another record. If you set the Default View property of the form to Continuous Forms, you can see multiple records on a short form and you can use the scroll bar on the right side of the form to scroll through the records. Because one record’s data in the tblEmployees table fills your employees form, the Single Form setting is probably the best choice.

Another set of properties lets you control whether a user can change to Form view, Datasheet view, PivotTable view, or PivotChart view. These properties are Allow Form View, Allow Datasheet View, Allow Pivot Table View, and Allow Pivot Chart View. The default setting for all these properties is Yes, meaning that a user can use the toolbar or the View menu to switch between any of the views. If you’re designing a form to be used in an application, you will usually want to eliminate some of the views. For your employees form, set all but the Allow Form View property to No; the Datasheet View, PivotTable View, and PivotChart View options on the Form View toolbar button’s drop-down list should become unavailable (appear dimmed).


TIP:
Keep users out of Design view

You can make it more difficult to enter Design view by designing a custom menu and toolbar for all your forms. See Chapter 24, "The Finishing Touches," for details. There are only two ways to completely prevent a user from opening a form in Design view or switching to Design view. You can secure the database (see Chapter 30, "Securing Your Database"), or you can give your users an execute-only copy of your application (see Chapter 31, "Distributing Your Application").

Setting Navigation Options

Because the employees form you’ve been designing displays one record at a time, it is not useful to display the row selector on the left side of the form. You’ve also designed the form to show all the data in a single window, so a scroll bar along the right side of the window isn’t necessary. You also don’t need a horizontal scroll bar. You probably should keep the Record Number box at the bottom of the form, however. To make these changes, set the form’s Record Selectors property on the property sheet to No, the Scroll Bars property to Neither, and the Navigation Buttons property to Yes. Your form should look something like the one shown in Figure 12-26.

Figure 12-26.

Figure 12-26. The employees form with views restricted and without a record selector or scroll bars.

Defining a Pop-Up and/or Modal Form

You might occasionally want to design a form that stays on top of all other forms even when it doesn’t have the focus. Notice that the toolbox, property sheet, and field list in Design view all have this characteristic. These are called pop-up forms. You can make your employees form a pop-up form by setting the form’s Pop Up property to Yes. Figure 12-27 shows the employees form as a pop-up form on top of the Database window, which has the focus. Note that the form can "float" on top of other forms or windows, and it can also be moved over the toolbars and menu bars. A form that isn’t a pop-up form cannot leave the Access workspace below the toolbars.

Figure 12-27.

Figure 12-27. The employees form as a pop-up form on top of the Database window.


CAUTION:
If you play with the frmXmplEmployee5 form to do this, be sure to set the form’s Pop Up property back to No or don’t save your design changes when you close the form.

As you’ll learn in Part 5, "Automating an Access Application," it’s sometimes useful to create forms that ask the user for information that’s needed in order to perform the next task. Forms have a Modal property that you can set to Yes to "lock" the user into the form when it’s open. The user must make a choice in the form or close the form in order to go on to other tasks. When a modal form is open, you can switch to another application but you can’t select any other form, menu, or toolbar button in Access until you dismiss the modal form. You’ve probably noticed that most dialog boxes are modal forms. Modal isn’t a good choice for your employees form, but you’ll use the Modal property later to help control application flow.

Controlling Edits, Deletions, Additions, and Filtering

You can set several form properties to control whether data in the form can be updated or whether data in the underlying tables can change. You can also prevent or allow user-applied filters on the form. These properties and their settings are shown in Table 12-9.

Table 12-9. Form Properties for Controlling Editing and Filtering

Property Description
Filter Contains the latest criteria applied as a filter on this form. Forms also have a FilterOn property that you can’t see in the Form window in Design view. When FilterOn is True, the data displayed in the form is filtered by the criteria string found in the Filter property. On a new form, the Filter property is empty.
Order By Contains the latest sorting criteria applied to this form. Forms also have an OrderByOn property that you can’t see in the Form window in Design view. When OrderByOn is True, the data displayed in the form is sorted by the criteria string found in the Order By property. On a new form, the Order By property is empty.
Allow Filters Determines whether a user can see selected records by applying filtering and sorting criteria and whether the user can see all records by choosing the Show All Records command from the Records menu. If you set the Data Entry property to Yes and set the Allow Filters property to No, the user can enter only new data and cannot change the form to view other existing records. The valid settings for the Allow Filters property are Yes and No. The default setting is Yes.
Allow Edits Determines whether a user can change control values in this form. The valid settings are Yes and No. The default setting is Yes. Note that when you set Allow Edits to No, you cannot change the value of any control on the form, including unbound controls.
Allow Deletions Determines whether a user can delete records in this form. The valid settings are Yes and No. The default setting is Yes.
Allow Additions Determines whether a user can add records using this form. The valid settings are Yes and No. The default setting is Yes.
Data Entry Determines whether the form opens a blank record in which you can insert new data. Access won’t retrieve rows from the form’s recordset. The valid settings are Yes and No, and the default setting is No. Setting Data Entry to Yes is effective only when Allow Additions is set to Yes.

Defining Window Controls

In some cases, you might want to prevent the user from opening the form’s Control menu (clicking the Control-menu button in the upper left corner of a window displays a shortcut menu containing the Restore, Move, Size, Minimize, Maximize, Close, and Next commands) or from using the Minimize and Maximize buttons. If you want to perform special processing before a form closes (such as clearing the application status before your main switchboard closes), you might want to provide a command button to do the processing and then close the form with a Visual Basic command. (See Part 5 for details about writing a command to close a form.) You can set the form’s Control Box property to No to remove the Control-menu icon from the form window and the Close button from the upper right corner. This also removes the Minimize and Maximize buttons.

You can set the form’s Close Button property to No to remove the Close button but leave the Control-menu button (with Close disabled on the Control menu). You can set the form’s Min Max Buttons property to Both Enabled, None, Min Enabled, or Max Enabled. If you disable a Minimize or Maximize button, the related command on the form’s Control menu becomes disabled. Finally, you can set the Whats This Button property to Yes to display the Help button, but to do this you must set the Min Max Buttons property to No.


CAUTION:
You can set a form’s Control Box property to No to remove all control features from the form’s title bar. This means that both the Control-menu button (which contains the Close command) and the form’s Close button (at the right end of the title bar) will not appear. If you also set the form’s Modal property to Yes, you should always provide an alternative way to close a modal form, such as a command button that executes a macro or Visual Basic command to close the form. Otherwise, the only way to close the form is to use the Windows Ctrl+F4 key combination. See Part 5 for details about writing a command to close a form.

Setting the Border Style

In most cases, you’ll want to create forms with a normal border—one that allows you to size the window and move it around. Forms have a Border Style property that lets you define the look of the border and whether the window can be sized or moved. The Border Style property settings are shown in Table 12-10.

Table 12-10. Settings for the Border Style Property

Setting Description
None The form has no borders, Control-menu button, title bar, Close button, or Minimize and Maximize buttons. You cannot resize or move the form when it is open. You can select the form and press Ctrl+F4 to close it unless the form’s Pop Up property is set to Yes. You should write Visual Basic code to provide an alternative way to close this type of form.
Thin The form has a thin border, signifying that the form cannot be resized.
Sizeable This is the default setting. The form can be resized.
Dialog If the Pop Up property is set to Yes, the form’s border is a thick line (like that of a true Windows dialog box), signifying that the form cannot be resized. If the Pop Up property is set to No, the Dialog setting is the same as the Thin setting.

Understanding Other Form Properties

Table 12-11 describes form settings not yet discussed and explains their usage. The table lists the properties in the sequence you will find them on the All tab in the Properties window.

Table 12-11. Other Form Properties

Property Description
Recordset Type The default setting, Dynaset, specifies that all controls bound to fields in the record source will be updatable as long as the underlying field would also be updatable. If your form is bound to a query, see the section "Limitations on Using Select Queries to Update Data," page 323. Dynaset (Inconsistent Updates) specifies that all fields (other than fields resulting from expressions or AutoNumber fields) can be updated, even if the update would break a link between related tables. (I do not recommend this option because it can allow a user to attempt to make a change that would violate integrity rules.) Snapshot specifies that the data is read-only and cannot be updated.
Record Locks No Locks (the default) specifies that Access will not lock any edited row until it needs to write the row back to the table. This is the most efficient choice for most applications. Edited Record specifies that Access apply a lock to the row the instant you begin typing in the record. This can lock out other users in a shared environment. All Records (not recommended) locks every record in the record source as soon as you open the form.
Dividing Lines When you design your form with a Header or a Footer section, Yes (the default) specifies that you will see a horizontal line separating each section. No removes the line(s).
Auto Resize The default Yes setting automatically resizes the form window to its design height and width when you open the form. Choose No if you want to set a specific window size.
Auto Center Choose No (the default) to open the form on the screen wherever it was placed when you last saved its definition from Design view or Form view. Choose Yes to automatically center the form in the Access workspace when you open it.
Width Specifies the width of the form in inches or centimeters. Access automatically updates this property when you drag the right edge of the design area wider or narrower in Design view. You cannot set this property to nothing (blank).
Picture Enter the path and file name of a graphic file to use as the background of the form. You can click the Build button next to the property to locate the picture you want. You might find this useful to display an image such as a company logo on the background of your forms.
Picture Type Choose Embedded (the default) to store a copy of the picture in your form design. Use Linked to save space in your database, but the form must then always load the picture from the specified Picture path when it opens; if you move the picture to a different location, it might not be displayed.
Picture Size Mode Clip (the default) specifies that the picture appear in its original resolution. If the form is larger than the picture, the picture will not cover the entire form area. If the form is smaller than the picture, you’ll see only part of the picture. Use Stretch to stretch the picture to the dimensions of the form, but the picture might appear distorted. Use Zoom to stretch the picture to the dimensions of the form without distorting it; but if the aspect ratio of the picture does not match the display space of the form, the picture won’t cover the entire form background.
Picture Alignment This property applies only when Picture Size Mode is Clip or Zoom. The default setting, Center, centers the picture in the form window area. Form Center centers the picture in the form design area. You can also specify that the picture align in the top left, top right, bottom left, or bottom right corner of the form.
Picture Tiling The default setting, No, places one copy of the picture on the form. Choose Yes if you want multiple copies "tiled" on the form. When you choose Yes, you must set Picture Alignment to Clip or Zoom, and the picture should be smaller than the form design or form window. Setting Picture Tiling to Yes is useful if your picture is a small pattern bitmap.
Cycle Use the default setting, All Records, to tab to the next record when you press the Tab key in the last control in the tab order. Choose Current Record to disallow tabbing from one record to another. Choose Current Page on a multi-page form to disallow tabbing onto the next or previous page—you must use Page Up or Page Down to move between pages. When you set Current Record or Current Page, you must use the navigation buttons or menu commands to move to other records.
Menu Bar, Toolbar, and Shortcut Menu Bar You can design a custom menu bar, toolbar, and shortcut menu for your forms and reports, and you enter the name of your custom menus or toolbars in these properties. See Chapter 24, "The Finishing Touches," for details.
Shortcut Menu The default setting, Yes, indicates shortcut menus will be available for the form and all controls on the form (either the built-in ones or ones you design). Choose No to disable shortcut menus.
Layout for Print The default setting, No, indicates that printer fonts installed on your machine will not be available in any font property settings, but screen fonts and True Type fonts will be available. Choosing Yes disables screen fonts but makes printer fonts and True Type fonts available.
Fast Laser Printing The default setting, Yes, specifies that Access will use laser printer line fonts to draw lines and rectangles if you print the form on a printer that supports this option. Choose No to send all lines to your printer as graphics.
Help File When you create a custom help file for your application, enter the path and file name in this property. See Chapter 24, "The Finishing Touches," for details.
Help Context ID You can create a custom Help file for your application and identify specific topics with a context ID. If you want a particular topic to appear when your user presses F1 when using this form, enter the ID of the topic in this property. If the focus is in a control that also has a Help Context ID defined, the topic for that control is displayed. See Chapter 24, "The Finishing Touches," for details.
Subdatasheet Height and Subdatasheet Expanded These properties are identical to those that you can define for tables and queries. Your form must be in Datasheet view and must have a subform that is also in Datasheet view. See Chapter 13, "Advanced Form Design," for details.
Palette Source Enter the name of a graphic file or Windows palette file that provides a color palette to display this form. You might need to set this property if you have also set the Picture property so that the colors of the background picture display properly. The default setting, (Default), uses your current Windows palette.
Tag You can use this property to store additional descriptive information about the form. You can write Visual Basic code to examine and set this property or take a specific action based on the property setting. The user cannot see the contents of the Tag property.
On Current through After Final Render You can set these properties to run a macro, a function, or an event procedure when the specific event described by the property occurs for this form. See Part 5 for details.
Has Module If you create Visual Basic event procedures for this form, Access automatically sets this property to Yes. If you change this property from Yes to No, Access warns you that doing so will delete all your code and gives you a chance to cancel the change. See Part 5 for details.
Orientation The default in most versions of Microsoft Access is Left-to-Right. In versions that support a language that is normally read right to left, the default is Right-to-Left. When you use Right-to-Left, captions appear right-justified, the order of characters in controls is right to left, and the tab sequence proceeds right to left.
Allow Design Changes The default, All Views, allows you to continue to make design changes when in Form view. The Formatting toolbar is displayed, and you can see the Properties window if it is open. Choose Design View Only before you release your application to your users.
Moveable The default setting, Yes, allows the user to move the form in the Access window. Set this property to No to lock the form on the screen where you last saved it.
Fetch Defaults Choose Yes (the default) to have the form fetch the default values from the field definitions when you move to a new row. Set this property to No to use only the Default Value settings you have specified for controls.

Setting Form and Control Defaults

When you’re building an application, you should establish a standard design for all your forms and the controls on your forms. Although you can use the AutoFormat templates, you might want to create a standard design that is different.

Changing Control Defaults

You can use the Set Control Defaults command on the Format menu to change the defaults for the various controls on your form. If you want to change the default property settings for all new controls of a particular type, select a control of that type, set the control’s properties to the desired default values, and then choose the Set Control Defaults command from the Format menu. The settings of the currently selected control will become the default settings for any subsequent definitions of that type of control on your form.

For example, you might want all new labels to show blue text on a white background. To make this change, place a label on your form and set the label’s Fore Color property to blue and its Back Color property to white using the Fore Color and Back Color toolbar buttons. Choose the Set Control Defaults command from the Format menu while this label is selected. Any new labels you place on the form will have the new default settings.

Working with AutoFormat

After you define control defaults that give you the "look" you want for your application, you can also set these defaults as an AutoFormat that you can use in the form wizards. To create an AutoFormat definition, open the form that has the control defaults set the way you want them and then click the AutoFormat button on the toolbar or choose AutoFormat from the Format menu. Click the Customize button to open the dialog box shown in Figure 12-28. Select the Create a new AutoFormat option to save a format that matches the form you currently have open, and then click OK. In the next dialog box, type a name for your new format and then click OK. Your new format will now appear in the list of form AutoFormats. As you saw in Chapter 11, "Building a Form," you can select any of the form AutoFormats to dictate the look of a form created by the form wizards.

Figure 12-28.

Figure 12-28. Creating a new AutoFormat definition.

If you have previously defined an AutoFormat, you can update it or delete it using the AutoFormat dialog box. You can also update or delete any of the built-in formats.

Defining a Template Form

You can also create a special form to define new default properties for all your controls. To do this, open a new blank form and place on it one of each type of control for which you want to define default properties. Modify the properties of the controls to your liking, use these controls to reset the control defaults for the form (by choosing Set Control Defaults from the Format menu for each control), and save the form with the name Normal. The Normal form becomes the form template for the current database. Any new control that you place on any new form created after you define your form template (except forms for which you’ve already changed the default for one or more controls) will use the default property settings you defined for that control type on the Normal form. Note that defining a form template does not affect any existing forms. Also, you can revert to the standard settings by deleting the form Normal from your database.

To define a name other than Normal for your default form and report templates, choose Options from the Tools menu, and then click the Forms/Reports tab. Enter the new name in the Form Template text box. Then save your template under the new name you specified on the Forms/Reports tab. Note that this new setting becomes the default for all databases on your machine, but if Access doesn’t find a form in your database with the name you specified, it uses the standard default settings instead.

If you want to see how this works in the HousingDataCopy.mdb sample database, choose Options from the Tools menu. On the Forms/Reports tab, enter zsfrmTemplate in the box under Form template, and click OK. Next, click the Forms button in the Object list in the Database window, and double-click the Create form in Design view option at the top of the window. Your new form should have a header and footer and the rice paper background. Try dropping a few controls onto the form. Although I started with the Rice Paper template, I modified the look of labels, text boxes, combo boxes, list boxes, and command buttons in the template form to be different. Figure 12-29 shows you my template in Design view. Note that your new form not only inherits control properties but also the height and width of each of the sections from the template.

Figure 12-29.

Figure 12-29. The zsfrmTemplate sample template form in the HousingDataCopy.mdb sample database.


CAUTION:
Be sure to change your default template name back to Normal before going on to the next chapter. This setting affects all your databases, but won’t hurt anything unless you happen to have a form named zsfrmTemplate in some of your databases.

Now you should be comfortable with designing forms and adding special touches to make your forms more attractive and usable. In the next chapter, you’ll learn advanced form design techniques: using multiple-table queries in forms, building forms within forms, and working with ActiveX controls, PivotTables, and PivotCharts.


Previous  |   Table of Contents     


Last Updated: June 17, 2004
Top of Page

   Contact Us    Free Newsletters   
   © 2004 Microsoft Corporation. All rights reserved. Terms of Use.    Privacy Statement    Accessibility