|
Chapter 12: Customizing a Form (continued)Setting Form PropertiesIn 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 ViewsWhen you build a form from scratch (such as the employees form youve been working on in this chapter), the Default View property of the form is Single Form. This is the view youll 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 records 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 youre 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 buttons 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 OptionsBecause the employees form youve been designing displays one record at a time, it is not useful to display the row selector on the left side of the form. Youve also designed the form to show all the data in a single window, so a scroll bar along the right side of the window isnt necessary. You also dont 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 forms 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. The employees form with views restricted and without a record selector or scroll bars. Defining a Pop-Up and/or Modal FormYou might occasionally want to design a form that stays on top of all other forms even when it doesnt 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 forms 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 isnt a pop-up form cannot leave the Access workspace below the toolbars.
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 forms Pop Up property back to No or dont save your design changes when you close the form. As youll learn in Part 5, "Automating an Access Application," its sometimes useful to create forms that ask the user for information thats 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 its 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 cant select any other form, menu, or toolbar button in Access until you dismiss the modal form. Youve probably noticed that most dialog boxes are modal forms. Modal isnt a good choice for your employees form, but youll use the Modal property later to help control application flow. Controlling Edits, Deletions, Additions, and FilteringYou 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
Defining Window ControlsIn some cases, you might want to prevent the user from opening the forms 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 forms 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 forms 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 forms 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 forms 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 forms Control Box property to No to remove all control features from the forms title bar. This means that both the Control-menu button (which contains the Close command) and the forms Close button (at the right end of the title bar) will not appear. If you also set the forms 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 StyleIn most cases, youll want to create forms with a normal borderone 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
Understanding Other Form PropertiesTable 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
Setting Form and Control DefaultsWhen youre 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 DefaultsYou 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 controls 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 labels 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 AutoFormatAfter 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. 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 FormYou 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 youve 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 doesnt 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. 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 wont 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, youll learn advanced form design techniques: using multiple-table queries in forms, building forms within forms, and working with ActiveX controls, PivotTables, and PivotCharts. Last Updated: June 17, 2004
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||