This Document is Deprecated and is therefore no longer maintained or updated. Some of the information may be out of date.

 Access XP/2000: Controls


 What are Controls?

Access is designed to provide database developers with a lot of flexibility. Part of this flexibility is having different types of objects that carry out quite specific functions. For instance, tables contain structured data, queries allow the user to work with that data, forms present your data and help you to automate database navigation and functions, and reports gather your data for printing.

Controls are graphical objects that a database developer places on a form or report. Controls can display data, perform actions specified by the user, or even help enhance the appearance of the database front-end. In fact, all information on forms or reports is contained in controls. Because there are many different controls that can do many different things, controls add to the flexibility of Microsoft Access.

 Basic Types of Controls

Forms and Reports often draw information from Tables or Queries by linking (or binding) controls to fields in an underlying table or query. Yet controls do not have to be bound. Thus, there are three basic types of controls in Access: unbound, bound, and calculated, which is an advanced form of binding.

  • Unbound: This control displays data that is not stored in an underlying table or query. For example, the title of the form, a picture, or a descriptive label. Unbound controls enhance the presentation, organization, and clarity of your form or report.

  • Bound: A bound control, in most cases, is linked to a specific field in the form's underlying table or query. This field is called the control's data source. Either a bound control displays records from a field, or it gives the user the opportunity to enter new data in a field. Bound controls can display hyperlinks, graphics, and other objects, as long as these objects are contained in the underlying table or query.

    Note

    For more information on linking forms and reports to underlying tables or queries, go to the ITS site [ http://help.unc.edu/?id=1910 ] Microsoft Access XP/2000 Users: Forms and Reports.

  • Calculated: Calculated controls are a subset of bound controls, but they do not present information as it appears in a table or query. Instead, they operate on data taken from the table or query by using an expression - a combination of operators such as +, -, =, and &, control names, field names, and constant values. For example, the following expression would combine entries in a table's First_Name field and Last_Name field to present them together with a space in between:

    =First_Name & " " & Last_Name

    This expression would appear in the control itself when in Design View, and the user will see the actual name based on two fields in the underlying table or query, such as "Tracy Jones."

Note

See "About Expressions," "Creating Expressions," and "Examples of Expressions" in Microsoft Access Help for more information on expressions.

Note

For more information on Design View of forms and reports, go to the ITS site [ http://help.unc.edu/?id=1910 ] Microsoft Access XP/2000 Users: Forms and Reports.

 The Toolbox

The Toolbox is a special kind of toolbar that appears only in Design View and contains icons that allow you to select the type of control or tool that best suits your needs. If the toolbox is not visible in Design View, you can activate it by selecting Toolbox from the View menu, or by selecting the Toolbox icon on the toolbar:

The toolbox icon

You can deactivate the toolbox the same way. Controls are created when the user presses one of the icons on the toolbox (each of which represents a different control) and then drags the cursor or clicks the mouse on the form or report body.

 The Properties Window

After creating a control, you can manipulate its properties through the Properties window. To access the Properties window, select Properties from the View menu item on the toolbar, or select the Properties icon also on the toolbar:

The Properties Window icon

The Properties Window contains all the property information for each control in the form or report. This includes the control's name, position on the screen, color, size, event properties, and data source properties. To access a control's properties, the user must make sure that the Properties Window is open and then select a control on the form or report. That control's properties will then appear in the Properties Window. A control's properties may be viewed or changed in the Properties Window. Below is a Properties Window for a text box (called "lastName"), which is a kind of control:

The Properties Window

Notice that the tab All is selected. This means that all the control's properties are listed. The other tabs organize properties by function: Format contains all the control's formatting properties (such as size and position), Data contains all the control's data source properties (e.g. to what field in an underlying table or query the control is bound), Event contains all the control's event properties (i.e. properties that define how the control will respond to user interaction like clicking or double clicking), and Other contains all miscellaneous properties, such as the control's name.

If you want several controls to have the same properties, such as color or width, you can set the properties of these controls simultaneously. After selecting one control, select all the other controls you want changed while holdind down the <Shift> key. Then change the properties in the Properties Window.

Some properties, such as name, style, and position properties exist for all controls. Others, such as various event and data source properties, exist for some controls and not others.

 Individual Controls

The toolbox controls belong to five major categories (listed below) and each control has a corresponding icon that appears on the toolbox.

 Text Boxes and Labels

Text boxes and labels are the default tools for looking at information in an Access form or report. Text boxes usually display data from a field in the underlying table or query, either directly or after Access performs calculation on the data. Labels, on the other hand, are usually captions or descriptive text entered directly by the database developer. Thus, text boxes are usually bound whereas labels are always unbound. Labels can be attached to other controls, however. Every text box you create on your form or report will automatically have an attached label, which can be subsequently used or deleted.

Another difference between the two is that text boxes can be interactive with the user while labels never are. Often, users enter information into text boxes and change data presented in text boxes. On the other hand, the user has no control over what is contained in a label.

Labels and textboxes can be created through the following icons on the toolbar:

Textbox and Label Control icons

Labels and textboxes appear as follows in Design View when they are first created:

Text box and label examples

You can bind the text box to the underlying table or query by clicking the text area in the Properties Window next to Control Source under the Data tab. A down arrow appears on the right. Click that and a list of all the fields in the underlying table or query appears. Select one and this will be the field that the control will be based on. The name of the field will then appear in the text box. When the user navigates his way through the underlying table or query using the form, each value in the underlying field will appear in the text box.

Notice also that Access provides default names for controls. It is usually a good idea to rename controls after you make them. You do this by selecting the control and entering its new name in the Name field under the Other tab in the Properties window. It's best to name a control as descriptively as possible to indicate what the control is and what its source is, such as txtLastName: "txt" indicates that the control is a text box, "LastName" that the text box is bound to the last name field in the underlying table or query.

 Yes/No Options

The toolbox contains three different kinds of controls that display boolean, or yes/no values: check boxes, option buttons, and toggle buttons. The icons for these controls, as they appear on the toolbox, are shown below:

Yes/No Controls icons
  • Check Boxes: This control, when selected, is a check mark in a small box. When it is de-selected, the box is empty. A selected check box indicates a "yes" value. An empty check box indicates a "no" value. Like text boxes, each check box is created with an attached label.

    Check boxes can be grouped by a control called an Option Group. The icon for option groups on the toolbox appears as so:

    The option group icon

    This is essentially a sizable frame that helps organize check boxes and option boxes (see below) on the screen. Within an option group of check boxes, any, none, or all of the check boxes may be selected at one time.

  • Option Buttons (AKA radio buttons): This control, when selected, is a dot in a small circle. When it is de-selected, the circle is empty. A selected option button also indicates a "yes" value. An empty option button indicates a "no" value. Each option button also comes with a label attached to it.

    Within an option group of option buttons, only one option button may selected at one time. When an option button is selected, the previously selected option button becomes empty.

  • Toggle buttons: Like check boxes and option buttons, toggle buttons indicate a choice between two values. When it is not selected, a toggle button looks like an unpressed button and has a "no" value. When it selected, it becomes a pressed button and has a "yes" value.

    Unlike check boxes and option buttons, you can control the appearance of toggle buttons. Next to the Caption property under the Format tab in the Properties Window, you can enter text that will appear upon the toggle button. Beneath this property in the Properties Window, the Picture property allows you to browse and select a graphic that will appear on the toggle button.

One feature that all yes/no option controls have in common is that they require user input. Whenever the user interacts with a database, this interaction is called an event. Selecting or de-selecting one of these controls is an event.

You can program an Access control to respond to an event by assigning event properties under the Event tab in the Properties Window. Here there will be a list of events such as "On Click" and "On Dbl Click" These are descriptions of ways the user can create events by interacting with the database (i.e. by clicking or double clicking on the control). In each of the text fields to the right of the events you can select a macro or enter an expression that will cause Access to perform a certain task when an event occurs, such as a certain text box being enabled or disabled when a check box is selected or de-selected.

See "About Setting the Value of a Control or Property in Response to an Event," "Set the Value of a Property in Response to an Event," and "Example of Setting the Value of a Property in Response to an Event" in Microsoft Access Help for more information on events and event properties. Also, see "About Macros and Macro Groups" and "Modify Macros" in Microsoft Access Help to learn more about macros in Access.

You will note that when you select a label and press the Event tab in the Properties window, no event list appears. This is because no event can occur with a label since labels are purely descriptive and do not allow user interaction of any kind.

Note also that yes/no controls can appear on a report, but the user will not be able to select them since reports also do not allow user interaction other than using the navigation buttons at the bottom of the screen.

 Drop-Down Boxes

Access' toolbox contains two types of drop-down boxes: a List box and a Combo box.

Combo and List box icons
  • List Box: As its name suggests, a list box displays a list of entries or values in column format. These entries or values can be culled directly from a field or fields in an underlying table or query or they can be entered by the database developer. Either of these tasks can be performed with the List Box Wizard, which appears every time a list box is created.

    The List Box Wizard is series of dialog boxes that ask you questions about how you wish to design the object in question. The first screen in the List Box Wizard asks if you want to base your list box on a table or query or if you want to type in the values yourself. If you decide to base it on a table or query, the Wizard takes the following steps with each new dialog box:

    1. It asks you what table or query on which you wish to base your list box.

    2. It asks you to select the field or fields from this table or query that you wish to represent in your list box.

    3. It asks you to size your columns (optional).

    4. It asks you to provide a caption for the label that comes attached to the list box. If you don't do this, Access provides a default caption.

    If you wish to type in the rows of the list box yourself, the Wizard allows you to enter values into cells as if you were creating a spreadsheet. You can enter in as many rows and columns as you like. It also asks you to provide a caption for the label that comes attached to the list box. The List Box Wizard is optional. You can press Cancel to exit the List Box Wizard at any time.

    Note that the user can interact with a list box by clicking on a row. This selects the row. Through the Event tab, the list box control can be instructed to respond to such events, just like the yes/no controls.

    You can allow single or multiple selections in a list box. Simply select the list box, press the Other tab in the Properties window, and click to the right of the Multi Select field.

    The default value for this field is "None," meaning only single selections are allowed. If you select "Simple," then multiple selections will be allowed. When in "Simple" mode, you can de-select a selected row by clicking on it again. If you select "Extended," Access enables you to make multiple selections by clicking one row and then pressing <Shift> while selecting another row. The method selects all the rows in between the two rows.

  • Combo Box: These controls are very similar to list boxes in that they display a list of values from which you can select. The primary difference is that you can see only one at a time (as in a text box), and if you wish to see the entire list, you select the down arrow on the right of the control, and the entire list appears. In fact, the Properties window is filled with combo boxes. Every time you selected a down arrow and a list appeared below a field, you've been using combo boxes.

    You will note that the Combo Box Wizard is identical to the List Box Wizard. You will also note that since a combo box can select only one row at a time, there is no Multi Select property for combo boxes.

A final note for list and combo boxes: the most effective way to present values from a table in these controls is to create a query that extracts all the unique values from a table and sorts them. Thus, your data will appear sorted in the list or combo box.

 Graphics Objects and Subforms

Forms can be enhanced by including different kinds of graphics objects or including other forms inside the main form or report. The icons of the four major controls in this category, as they appear on the toolbox, are shown below:

Graphics controls and subform controls icons
  • The Image Control: This control allows you to search for and insert a graphic into your form or report.

  • The Subform/Subreport Control: This control lets you insert a pre-existing form into your current form or report. This is accomplished through the SubForm Wizard or the SubReport Wizard, both of which are very similar to the List Box and Combo Box Wizards.

  • The Bound and Unbound Object Frames: These controls allow you to insert onto your form or report pictures or other OLE objects.

 Layout Enhancement Controls

You can improve the appearance of your forms with the Line Control, the Box Control, or the Page Break Control. The icons for these controls are shown below:

Layout enhancement controls icons
  • The Line and Box Controls: These controls designate sections of your form or report that you want to separate visually from other sections.

  • The Page Break Control: This allows you to control how much information goes on one page of each form or report.

 The Field List

Another way to add a control to a form or report is to use the Field List. When a form is bound to a particular table or query, a Field List appears that lists all the fields of the underlying table or query. To make this list disappear, select the following Field List icon on the toolbar:

The Field List icon

To make it appear again, click the same icon or select Field List under the View menu item on the toolbar. When both the Field List and the Toolbox are displayed, you can select the control type that you want to add in the Toolbox and then drag the field you want bound from the Field List to the form's design grid. The default control is the text box, which means that if you drag a field onto the form or report without first selecting a control, a text box displaying records of the chosen field will appear. If you select an inappropriate control (e.g. the Line control) a text box will also appear. In most cases, the alternatives to text boxes are list and combo boxes.

 Selecting, Moving, and Sizing Controls

Access has easy drag-and-drop movement of controls in forms and reports. You select a control by clicking on it; once a control is selected, you should see "handles" appearing around it. These are small boxes that you can use to resize and move the control. You can also select several adjacent controls by "lassoing" them. To lasso, you need to click in an open space on the form or report, then drag the pointer through all of the controls that you want to select. Make sure that you start lassoing from a point that will allow you to drag through all of the desired controls without intersecting any others. To select controls that are not adjacent, begin by clicking on the first control and select subsequent controls by clicking on them while holding down the <Shift> key. Once selected, you can move a control and its attached label anywhere in the form by dragging it to a new location.

There are three ways to use the handles of a control. These three ways are represented by the three images that the cursor turns into when you select a control and then place the cursor on its border:

  • Open Hand: The cursor becomes an open hand whenever the cursor crosses over the border of a control but not one of its handles. An open hand indicates that you can click on the control and move it along with its attached label.

  • Double-Headed Arrow: The icon becomes a double-headed arrow whenever it passes over one of the control's handles except for the upper left handle (which is slightly bigger than the other handles). This means that you can click on the control and resize it by dragging the cursor across the form or report.

  • Hand With Index Finger Pointing Up: The cursor becomes a hand with the index finger pointing up (just as it normally does when passing over a link on a webpage) whenever the cursor crosses over the control's upper left handle. This indicates that you can click on the control and move it without its attached label.

 Aligning Controls

Access allows you to place all your controls in their desired locations.

  • Aligning controls according to a grid: To make a grid appear on your form or report, go to Design View and select Grid under the View menu. You can also do this by right-clicking on the form or report and then selecting Grid in the menu that appears. A grid then appears. Select Snap To Grid in the Format menu. Access will then align any new control to points on the grid and it will align any controls you try to move or resize. You can align more than one control to the grid at one time as well. When selecting the controls, keep the <Shift> button pressed. This allows multiple selecting, and each selected control will then be aligned to the grid.

  • Aligning controls relative to each other: After selecting the controls you wish to align, select Align in the Format menu. Then in the menu that appears, select Right, Left, Top, or Bottom depending on how you want the controls aligned, as demonstrated with text boxes below:

    Example of unaligned controls and aligned controls

    Note that the Align menu also appears when you right-click on the selected controls.

 On-The-Fly Control Switching

Older versions of Access would not allow you to change one type of control into another. Instead, developers had to delete the control and create a new one. In the latest versions of Access however, you can make such on-the-fly changes by right-clicking the control in question and selecting Change To on the menu that appears.

There are, of course, limitations that apply. You cannot, for example, change a toggle button into a label. Thus, the Change To function is enabled only for similar controls. Text boxes, combo boxes, and list boxes can be changed into each other. All yes/no option controls can be changed into each other. Finally, text boxes can be changed into labels and vice versa.

Copyright 2002-2007 The University of North Carolina at Chapel Hill.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 United States License.

Post a Comment

This form is for document feedback. If you need technical assistance, and are affiliated with UNC-Chapel Hill, please Submit a Help Request
Optional
Optional
So that we may contact you.
Do not fill out this form, this is a spam trap.
Top
University of North Carolina - Chapel Hill