Lessons Logo

Overview of Windows Controls

Text-Based Controls: The Label

Introduction

A label is a control that serves as a guide to the user. It provides a static text that the user cannot change but can read to get information about another control on the form. You can also use it to display simple information to the user. Most controls on the form are not explicit at first glance and the user would not know what they are. Therefore, you can assign a label to the control as a help to the user.

To add a label to a form, on the Toolbox, click Label and click on the form or report. Type the text that the label will display and press Enter (as we will see, most controls add their own label to the form).

Properties of a Label

Probably the most important and the most obvious characteristic of a label is the text it is displaying. The text is the label's Caption. If you click the Label on the Toolbox and click on the form, you must first define its caption. If a label already has a caption, there are various ways you can edit it. For example, use the same techniques we reviewed for editing text-based properties. On the other hand, to edit the caption of a label, on the form, click inside the label. That would put it into edit mode and you can edit it as you wish.

The appearance of a label is visibly controlled by its font characteristics. The Font name, also called its face, is the name of the font as defined by the operating system. We saw that there are various ways you can define the font characteristics of a control like the label. The Formatting toolbar is equipped with appropriate combo boxes and buttons. These characteristics can also be modified using their corresponding properties from the Properties window.

The dimensions of a label control its Width and Height. Although the dimensions are closely related to the font characteristics, they can be independently defined. There are two main ways you can resize a label, which is equivalent to changing its dimensions. To set your own dimensions, in the Format tab of the Properties window of the label, change the values of the Width and Height properties. Unless you plan to show the background color of a label, probably the best way to resize a label is to make it adjust to the dimensions depending on the font size and the total characters width. To do this, position the mouse on one of the label's handle and double-click. The label's width and height would be set to accommodate its caption.

The position of a label is controlled by its Top and Left properties. The Top property defines the measure from the top left corner of the section where the label is positioned, to the top left corner of the label itself. There are two main ways you can set the position of a label. On the Properties window, you can change the values of the Top and Left properties. On the other hand, you can place your mouse on the top left corner of the label until the mouse pointer turns into a pointing finger. Then click and drag in the desired direction.

Practical Learning: Designing Labels

  1. Open the Video Collection1 database
  2. From the Forms section of the Database window, right-click the Videos1 form and click Design View
  3. From the Toolbox, click Label and click in the top left section under the Header bar. 
  4. Type Video Collection – Video Details and press Enter
  5. While the new label is still selected, on the Formatting toolbar, click the arrow of the Font combo box and select Garamond
  6. Click the arrow of the Font Size combo box and select 20 
  7. Click the Bold button Bold
  8. Click the arrow of the Font/Fore Color button and click Yellow (column 3 - row 4). 
  9. To resize the label, position the mouse on one of the handles surrounding the label and double-click
  10. To reposition the label, on the Format property page of the Properties window, click Left, type 0.25 and press Enter
  11. Change the value of the Top property to 0.040 
  12. While the label is still selected, on the Properties window, click the Other tab
  13. Click Name, type lblMainTitle and press Enter
  14. Click anywhere on the form (to deselect the label) 
  15. Right-click the Video Collection label and click Copy
  16. Right-click anywhere in the same Form Header section and click Paste
  17. While the new label is still selected, on the Properties window, click the All tab 
  18. Click Name and type lblShadowTitle 
  19. Click Left and type 0.29 
  20. Click Top and type 0.075 and press Enter
  21. On the Formatting toolbar, click the arrow of Font/Fore Color and click Dark Red (1st column - 2nd row). 
  22. On the Object combo box of the Formatting toolbar, select lblMainTitle and notice that it is selected on the form
  23. On the main menu, click Format -> Bring To Front
  24. Drag the top border of the Detail bar up completely to shrink the Form Header section until you cannot drag up anymore
  25. Before leaving, in the Form Header section, draw a fake line that touches both labels to select them. Then press Ctrl + C to copy
  26. To preview the form, on the Form View toolbar, click the View button
  27. On the menu bar, click Window -> Size To Fit Form:
  28. Close the form. When asked to save the form, click Yes. 
  29. On the Database Window, right-click the Actors1 form and click Design View
  30. Right-click the area under the Form Header bar and click Paste
  31. While both labels are still selected, in the Properties window, click the Format tab. Change or edit the value of Caption to display Video Collection – Actors/Actresses and press Enter
  32. Double-click one of the handles of the labels to resize them
  33. Preview, save and close the form

Text-Based Controls: The Text Box

Introduction

A text box is a Windows control used to get or display text for the user’s interaction. At its most regular use, a text box serves as a place to fill out and provide information. You can also use it only to display a text without allowing the user to change its content.

Like most other controls, the role of an edit box is not obvious at first glance; that is why it should be accompanied by a label that defines its purpose. From the user’s standpoint, a text box is named after the label closer to it. Such a label is usually on the left or the top side of the corresponding edit box. 

There are two main ways you can add a text box to a form:

Properties of a Text Box

Like every control on a form, the dimensions of the text box are controlled by its Width and Height properties. The position of a text box is controlled by its Top and Left properties. 

To make a text box read-only, that is, if you don't want the user to enter text in an edit box, there are various alternatives. If you change the Enabled property from Yes to No, the text box would have a gray background and cannot receive focus. If you set the Locked property from No to Yes, the control would appear with a normal (white) background. 

The Special Effects of the text box are expanded as compared to those available on a label. Besides the ability to raise or sink a text box, you can give it a thick, etched, or shadow border. 

After adding a text box on a form, you can configure it to receive its data from an existing table. This can be done after the Record Source of a form has been defined. To link a text box to the object that is the Record Source of a form, click the arrow of its Record Source combo box and select the desired field.

Practical Learning: Designing Text Boxes

  1. In the Forms section of the Database window, right-click the Actors form and click Design View
  2. On the form, click the Actor text box
  3. On the Formatting toolbar, click the arrow of the Special Effect button and click Special Effect: Shadowed
  4. Preview, save and close the form 

The Command Buttons

Introduction

A command button is a rectangular object that allows the user to dismiss a dialog box or to initiate an action. This is done through a decision making process based on what a form or a dialog box 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 or a dialog box. To use a button, the user position his mouse pointer 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 or dialog box is displaying. A caption like Cancel is usually accompanied by another OK button on the form. 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 Command Button control on the Toolbox and click on the desired section of the form. On the Toolbox, if the Control Wizard button was down or clicked, the Command Button Wizard would start to help you create a fully functional button. If you do not want to use the wizard, you can click Cancel on the first page of the Command Button Wizard. Also, if you do not want to use the wizard, on the Toolbox, you can click the Control Wizards button to have it up.

Practical Learning: Creating Command Buttons

  1. Open the Bethesda Car Rental1 database
  2. From the Forms section of the Database window, double-click the About1 dialog box to open it
  3. After viewing the dialog box, switch it to Design View
  4. On the Toolbox, after making sure that the Control Wizard button is down , click the Command Button control and click the empty area in the Form Footer section on the right side of the warning label
  5. On the first page of the Command Button Wizard, in the Categories list, click Form Operations
  6. In the Actions list, click Close Form
  7. Click Next
  8. On the second page, replace the content of the Text edit box with OK (and make sure the Text radio button has been selected) and click Next
  9. Change the name of the button to cmdOK and click Finish
  10. Resize the button as you see fit
  11. Preview the dialog box:
     
  12. Save the form. To close it, click OK

Characteristics of Command Buttons

Like all other “visual” controls, a command button has a Name property, a location (Left and Top), and dimensions (Width and Height). Because of their anticipated behavior, command buttons are the most commonly used object to initiate an action. As such, they are used to open other forms, reports of the same database, or simply to display a message box.

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 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.

Practical Learning: Configuring Command Buttons

  1. The Bethesda Car Rental1 database should still be opened.
    From the Forms section of the Database window, right-click the About1 dialog box and click Design View
  2. On the form, click the OK button to select it. In the Properties window, click the Other tab and double-click Default to change its value from No to Yes
  3. Save and preview the dialog box
  4. To close, press Enter

Combo and List Boxes

Introduction to Combo Boxes

A combo box is a Windows control made of two parts: a text portion and a list. A text box 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). This is done the same way we did with the table: using the Lookup Wizard.

Practical Learning: Creating a Combo Box

  1. Open Video Collection1 database and open the Videos2 form
  2. After previewing it, to switch it to Design View, on the Form View toolbar, click the View button
  3. On the toolbox, make sure the Control Wizard button is clicked 
  4. On the Toolbox, click the Combo Box button 
  5. On the form, click between the Title and the © Year text boxes:
     
  6. On the Combo Box Wizard dialog box, make sure the first radio button is selected and click Next
  7. In the list of tables, click Directors and click Next
  8. From the Availability Fields list, double-click Director and click Next
  9. Make sure the Hide Key Column check box is checked and click Next
  10. Click the arrow of the combo box and select DirectorID
     
  11. Click Next
  12. For the label of the combo box, type Director to replace the suggested label and click Finish
  13. Save the form and switch it to Form to preview it
  14. After viewing the form, switch it back to Design View

Introduction to List Boxes

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 her 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.

Practical Learning: Creating a List Box

  1. The Video Collection1 database should still be opened with the Videos1 form in Design View.
    On the Toolbox, make sure the Control Wizard button is clicked 
  2. On the Toolbox, click the List Box button
  3. On the form, click on the right side of the DirectorID combo box
  4. On the first page of the List Box Wizard, click the second radio button and click Next
  5. Click the empty field under Col1 and type G
  6. Press Tab and type PG
  7. Complete the list with the following options: PG-13, R, NC-17, X, and N/R
     
  8. Click Next
  9. Click the arrow of the combo box and select Rating
  10. Click Next
  11. For the label, type Rating and press Enter
  12. Save, preview, and close the form

Properties of Combo and List Boxes

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 behind-the-scene jobs. The Combo Box Wizard, used to create a bound combo box, is able to reconcile a relationship between the primary key of the parent table that holds the actual data to display, and the selected foreign key that exists on the table that host the foreign key. After creating the combo box, especially if you used to 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 you, the database application, or the operating system to identify it. If you create a combo box by dragging, 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 do not 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.

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

  1. Open the Bethesda Car Rental1 database
  2. In the Forms section of the Database window, double-click the RentalRates form to open it. If you do not have it, open the RentalRates1 form
  3. After viewing the form, switch it to Design View
  4. On the Toolbox, make sure the Control Wizard button is down 
    To create a list box, on the Toolbox, click the List Box button and, on the form, cl under Detail on the top-left section
  5. On the first page of the List Box Wizard, make sure the first radio button is selected and click Next
  6. In the list of tables, click Car Categories and click Next
  7. In the Available Fields list, click the select all button and click Next
     
  8. Make sure the Hide Key Column check box is checked and click Next
  9. Change the label to Rental Rate by Category and click Finish
  10. Preview the form in Form View and switch it back to Design View
  11. On the form, click the list box to select it
  12. On the Properties window, click the All tab. Click Name. Type lstRentalRates and press Enter
  13. Set the Column Heads property to Yes
  14. Change the Column Widths as follows: 0”;0.875”;0.85”;0.85”;0.85”;0.85”
  15. Resize the list box control and the form appropriately
     
  16. Save and preview the form
  17. Close the form

Radio Buttons

Introduction

A radio button is a Windows control made of a round box O. In practical usage, a radio button is usually (if not always) accompanied by other radio buttons. In other words, radio buttons come as a group. The user makes his or her decision by selecting or clicking one of the round boxes. Once clicked, the round box is partially filled with a dot. When one button in the group is selected, the other round boxes of the (same) group are empty O. The user can select another button by clicking a different choice, which empties the previous selection. This technique of selecting is referred to as mutually-exclusive.

There are two main ways you add a radio button to your form or report. While in Design View, if you add an Option Group control to a window while the Control Wizard button is down, the Option Group Wizard would start, allowing you to create a list of items where each item would be later converted into a radio button. If the radio button must be linked to a column of the data source, you will need to specify it. Such a column should have a natural number as data type (Byte, Integer, Long Integer).

Practical Learning: Adding Radio Buttons

  1. Open the Danilo Pizza1 database
  2. From the Forms section of the Database window, double-click the CustomersOrders form to open it
     
  3. After viewing the form, switch it to Design View
  4. On the Toolbox, make sure that the Control Wizards button is down .
    Click the Option Group control 
  5. On the form, click under the Processed By label 
  6. On the first page of the option Group Wizard dialog box, click the empty box under Label Names and type Small
  7. Press the down arrow key and type Medium
  8. Press the down arrow key, type Large
     
  9. Click Next
  10. To set the default choice, click the arrow of the combo box and select Medium
  11. Click Next
     
  12. Accept the values suggested for the option buttons and click Next 
  13. Click the arrow of the combo box and select PizzaSizeID because the option button selected will be held by, or carried by, or stored in, the PizzaSizeID foreign key
     
  14. Click Next
     
  15. Accept to have the Options Buttons with an Etched border. Click Next
  16. Change the Caption suggested to Pizza Size and click Finish

Properties of Radio Buttons

Because the round box of a radio button does not indicate what it is used for, it is usually (if not always) accompanied by a label. The label can be positioned anywhere (to the left, the top, the right, the bottom side) close to the round box but it is usually positioned to the left or the right side. To move or position the round box, click it to select it. Then position your mouse on it to get a pointing finger arrow and drag in the desired direction:

Like most (if not all) other controls, when you include a radio button, Microsoft Access adds a label to the control. If you do not like the string displayed by the label, you can click it twice to put it into edit mode and change the string.

Practical Learning: Configuring Radio Buttons

  1. The Danilo Pizza database should still be opened with the CustomersOrders form in Design View.
    On the form, click an unoccupied area to make sure nothing is selected. Click the border of the newly added Group Box (the line that surrounds the group and touches the Pizza Size label) to select the frame
  2. In the Properties window, click the All tab and click Name. Type fraPizzaSize and press Enter
  3. Enlarge the border of the option group to include the text boxes that correspond to the option buttons
  4. Save and preview the form
     
  5. Switch it back to Design View

Check Boxes

Introduction

A check box is a control that allows the user to validate or invalidate an option. A check box appears as a little square box £. The user makes his or her decision by clicking in the square, which toggles a check mark R. Toggling means, that if the square box were empty £, after clicking it, a check mark would appear in it R:

Although it can appear by itself, a check box can come in a group with others, allowing the user to select as many choices as are available, as opposed to radio buttons where only one in the group can be selected

Check boxes provide a non-exclusive choice, which means that if they come as a group, each can behave independently with regards to the other check boxes of the same group. Therefore you can create check boxes anywhere on the form. It is recommended that, when they act as an ensemble, you should include check boxes in a group so their belonging to the same group would be obvious to the user.

Practical Learning: Adding a Check Box

  1. The Danilo Pizza database should still be opened with the CustomersOrders form in Design View.
    On the Toolbox, click the Check Box control and click the group box under the Toppings label
  2. While the new check box is still selected, in the Properties window, click the All tab and click Name. Type txtPepperoni and press Enter
  3. In the Control Source, select Pepperoni
  4. On the form, click the label of the new check box. Click it again and edit its string to display Pepperoni
  5. From the Field List, drag Sausage and drop it in the group box under the Toppings label
  6. In the same way, drag the ExtraCheese, the Onions, and the Olives fields to the same group box
  7. Using the techniques of control resizing and moving, complete the design of the controls
  8. Save and preview the form
     
  9. Close the form
 

Toggle Buttons

 

Introduction

A toggle button is a type of button that behaves like a check box. The first difference is that it displays like a command button but behaves like a check box. The second difference is that, while a check box should be accompanied by a label that indicates what the check box is used for, a toggle button, like the command button, can display a string on its “face”.

To create a toggle button, you can click the Toggle Button control on the Toolbox and click the form. Like the check box and the radio buttons, there is no wizard to follow.

 

Properties of a Toggle Button

Configuring the toggle button is particularly easy. Like the check box, the toggle button should be used for a Boolean field. Therefore, after adding it to a form, in the Control Source of the toggle button, select the field that would carry or show its value.

 

MOUS Topics

S17 Use the Control Toolbox to add controls
S18 Modify Format Properties (font, style, font size, color, caption, etc.) of controls
 

Exercises 

 

Yugo National Bank

  1. Open the Yugo National Bank database
    Open the Customers table in Design View. Insert a new field just under CustomerID. Name it Created By and set its Data Type to Lookup Wizard. In the Lookup Wizard, select the LastName and Title fields from the Employees table. Keep the label as Created By and delete 0 as the Default Value. Save and close the table
  2. Open the Customers form in Design View and delete the AccountTypeID text box.
    Use the Combo Box Wizard to create a field for the AccountTypeID column. Include the AccountType field from the AccountTypes table. Store its values in the AccountTypeID field and set its label to Account Type. Change the Name of the combo box to cboAccountType
    Re-adjust the Tab Order then design the form as follows and save it before closing it:
     
  3. Open the Customers table in Design View. To make sure that only employees who are allowed to, can actually create new accounts, in the Lookup section of the EmployeeID field,  open the SQL statement. Add the CanCreateNewAccount field and set its Criteria to be True but don't show it to the user
     

     
    Save and close the table
  4. Create and design a form based on the Transactions table. Save it as Transactions
     

     
    Close the form
  5. Open the Transactions form and perform a few transactions then close it
  6. Using the Command Button Wizard, create a button used to close the form on each form of the database. Set the caption of the button as Close and name it cmdClose
 

Watts A Loan

  1. Open the Watts A Loan database.
    Design a form based on the LoanProcessing table
    Use the Combo Box Wizard to create a field for the EmployeeID column. Include the LastName and the Title fields of the Employees table. Make sure its values are stored in the EmployeeID field and set its label to Processed By. Change the Name of the combo box to cboEmployee.
    Use the Combo Box Wizard to create a field for the CustomerID column. Include the AccountNumber and the LastName fields from the Customers table. Make sure its values are stored in the CustomerID field and set its label to Account Number By. Change the Name of the combo box to cboCustomer
    Use the Combo Box Wizard to create a field for the TypeOfLoanID column. Include the TypeOfLoan field from the TypesOfLoan table. Make sure its values are stored in the TypeOfLoanID field and set its label to Type of Loan. Change the Name of the combo box to cboTypeOfLoan
    Using the items from the Field List, complete the design of the form as follows:
     

     
    Save and close the form
  2. Create a title with a shadow label in the Form Header section of each form as follows:
     
     
     
     
     
  3. Using the Command Button Wizard, create a button used to close the form on each form of the database. Set the caption of the button as Close and name it cmdClose
 

Previous Copyright © 2002-2005 FunctionX, Inc. Next