| A command button is an object that allows a person to use a dialog box or to initiate an action. This is done through a decision making process based on what a form is displaying. This could be an acknowledgement, such as a form displaying a simple message to the user. A user could also be asked to choose one button from a group of buttons on a form. To use a button, the user positions the mouse on the desired button and presses the left button. This action is referred to as clicking.
|
Depending on how the button is implemented, it should be obvious to the user what to do with it. To indicate what a button is used for or what action it would lead to, a button can display a string on its top. This string is also referred to as the button's caption. The caption should be explicit enough to let the user know what the button is used for. A caption like OK usually means the user accepts what message the form is displaying. A caption like Cancel is usually accompanied by an OK button. When a button has a Cancel button, the user would usually click it as if saying, "Never Mind" or "I change my mind", etc.
To create a button, you can click the Button

in the Controls section of the Design tab of the Ribbon and click the desired section of the form. If the Use Control Wizard option is on

, the Command Button Wizard would start to help you create a fully functional button. If you don't want to use the wizard, you can click Cancel on the first page of the Command Button Wizard. Also, if you don't want to use the wizard, in the Controls section of the Design tab of the Ribbon, click the More button and click the Use Control Wizards option to dimisss it

.
Practical Learning: Creating Command Buttons |
|
- Start Microsoft Access
- Open the Danilo Pizza from the previous lesson
- In the Navigation Pane, under the Forms bar, right-click PizzaOrders1 and click Design View
- Right-click the form and click Form Header/Footer
- In the Controls section of the Ribbon, click the More button
and click the Use Control Wizards to set it on 
- Click the Button
and click the empty area under the Form Footer bar of the form - On the first page of the Command Button Wizard, in the Categories list, click Form Operations
- In the Actions list, click Close Form

- Click Next
- On the second page, replace the content of the Text edit box with Close

- Click Next
- Change the name of the button to cmdClose

- Click Finish
- Resize the button as you see fit
- Switch the form to Form View

- To preview the form, right-click its tab and click Form View
- Click the Close button to close the form. If/when asked whether you want to save it, click Yes
Characteristics of Command Buttons |
|
Like all other "visual" controls, a button has a Name property, a location (Left and Top properties), and size (Width and Height properties). Because of their anticipated behavior, buttons are the most commonly used objects to initiate an action. As such, they are used to open forms or reports or to display message boxes.
As we saw in the second page of the wizard, a command button in Microsoft Access can display either a string or a (small) picture on top. Microsoft Access ships with dozens of pictures you can use, especially made for buttons. If none of these pictures suits your need, you can design your own. To display a picture on a button, after selecting it in Design View, click the ellipsis button of the Picture field in the Format tab of the Properties window, locate the picture, and select it.
When a dialog box is equipped with an OK and a Cancel button, it is suggested that the user be able to press Enter to perform the same action as if he had clicked OK. To apply this behavior, if you create a button and give it an OK caption, you can set its Default property to Yes. It is also suggested that, if a button has a Cancel Caption, the user should be able to press Esc and produce the same behavior as if the Cancel button was clicked. To apply this feature, after creating the button with a Cancel caption, set its Cancel property to Yes. Never set the Default and the Cancel properties both to Yes for the same button.
Microsoft Office Access 2010 brought new features to the design and appearance of a button. Once of the aspects you can control on the appearance of a button is its shape. To set it, while the form or report is in Design View and the button(s) is(are) selected, on the Ribbon, click Format. In the Control Formatting section, click Change Shape:
From there, click the desired shape.
Another aspect you can control on a button is its style. To use it, while the form or report is in Design View and the button(s) is(are) selected, on the Ribbon, click Format. In the Control Formatting section, click Quick Style:
From there, click the desired shape.
A combo box is a Windows control made of two parts: a text portion and a list. The text box portion is used to display a selection made from a list of items. On the right side of the text box, there is a down-pointing arrow that allows the user to know that the control holds a list. The user displays the list by clicking the arrow:
To use a combo box, the most basic operation the user can perform is to click the arrow and select an item. Once an item is selected, the list retracts back like a plastic.
There are various ways you can add a combo box to a form or report: using the Lookup Wizard or using the Combo Box Wizard:
- We will learn to create a combo box using the Lookup Wizard
- We will learn to create a combo box using the Combo Box Wizard in Lesson 33
The combo box is one of the highly praised features of Microsoft Access. As the application makes it particular easy to create, it performs all necessary basic tasks behind-the-scene jobs. The Combo Box Wizard, used to create a bound combo box, is able to reconcile a relationship between two tables. After creating the combo box, especially if you used the wizard to configure it, you can check and adjust the characteristics as you see fit.
Like every control, a combo box uses a name that allows the database application or the operating system to identify it. If you create a combo box by dragging an item from the Field List, a field whose lookup features have already been configured, the control would receive the same name as the table's column. If you create a combo box using the Combo Box Wizard, the control would receive a name that starts with Combo. An example would be Combo21. If you don't intend to refer to the combo box in an expression, you would not need to pay attention to the name of the control. Otherwise, if you create various controls using wizards, the names might become confusing. In this case it would be a good idea to change the name of the combo box. Like all others, to change the name of a control, access its Properties window and, from the Other or the All table, change the value of the Name property.
A list box presents a list of items to the user. The list appears as a taller text box. The items in the list appear each on its own line. The user makes a selection by clicking in the list. Once an item is clicked, it becomes highlighted indicating that it is the current choice:
Probably the easiest way to create a list is by using the List Box Wizard. This allows you to select the source of data, which would be a table or a query. Then you can select the column that would be displayed as the value of the list box, exactly as done for the combo box.
When we think of a list box, we usually assume that it is made of one column of items. A list box can be made of various columns. In this case, it is sometimes called a list view. Most of the time, when a multi-column list displays, the user may not be able to identify the items under each column. In this case, you can display a column header on its column. This column header would display a label that categorizes the items under it.
One of the main reasons for using a combo or a list box is to provide a list of items to the user. Sometimes the list would be very large. If the list is long, the control would provide a vertical scroll bar that allows the user to navigate up and down to access all items of the list. The database developer decides how many items to display in the list.
Practical Learning: Configuring a Combo Box |
|
- Open the Bethesda Car Rental1 database
- In the Navigation Pane, double-click Rental Rates to open it (you should have created this dialog box in Lesson 8; if you did not, use the Rental Rates1 dialog box)
- After viewing the form, to switch it, right-click its title bar and click Design View
- In the Controls section of the Ribbon, click the More button
and make sure the Use Control Wizards option is on
.
To create a list box, on the Ribbon, click the List Box button 
- Click the form

- On the first page of the List Box Wizard, make sure the first radio button is selected and click Next
- On the second page of the wizard, in the list of tables, click Table: CarCategories

- Click Next
- On the third page of the wizard, in the Available Fields list, click the select all button

- Click Next
- On the fourth page of the wizard, accept the defaults and click Next

- On the fifth page of the wizard, make sure the Hide Key Column check box is checked and click Next
- Change the label to Rental Rates by Category and click Finish
- On the form, make sure the list box selected or click it.
In the Properties window, click the All tab and click Name - Type lstRentalRates and press Enter
- Set the Column Heads property to Yes
- Change the Column Widths as follows: 0";0.875";0.85";0.85";0.85";0.85"
- Resize the list box control and the form appropriately
- Save and preview the form

- Close the form
EmoticonEmoticon