Microsoft Access includes the following types of controls, which are all accessible through the toolbox in Design view of a form, report, or data access page: text box, label, option group, option button, check box, list box, command button, tab control, image control, line, rectangle, and ActiveX custom controls. You can also add a Microsoft Office PivotTable list, an Office Chart, or an Office Spreadsheet to a form, report, or data access page.
Forms and reports have these additional controls: toggle button, combo box, bound object frame, unbound object frame, and page break. You can also add a subform or subreport to a form or report. Data access pages also include the drop-down list box, hyperlinks, scrolling text, and the PivotTable list, spreadsheet, and chart components.
Controls are objects on a form, report, or data access page that display data, perform actions, or are used for decoration. For example, you can use a text box on a form, report, or data access page to display data, a command button on a form to open another form or report, or a line or rectangle to separate and group controls to make them more readable.
All the information on a form or report is contained in controls. On data access pages, information is contained in controls in the same way as it is on forms and reports. However, information can also be typed directly on the data access page.
Controls that you can use to display, enter, filter, or organize data in Access
You use text boxes on a form, report, or data access page to display data from a record source. This type of text box is called a bound text box because it's bound to data in a field. Text boxes can also be unbound. For example, you can create an unbound text box to display the results of a calculation or to accept input from a user. Data in an unbound text box isn't stored anywhere.
These bound text boxes display data from the ProductName and UnitPrice fields in the Products table.
This unbound text box displays the result of a calculation.
You use labels on a form, report, or data access page to display descriptive text such as titles, captions, or brief instructions. Labels don't display values from fields or expressions; they're always unbound and they don't change as you move from record to record.
A label can be attached to another control. When you create a text box, for example, it has an attached label that displays a caption for that text box. This label appears as a column heading in the Datasheet view of a form. When you create a label by using the Label tool , the label stands on its own
Stand-alone label
Labels attached to text boxes
List boxes, combo boxes and drop-down list boxes
In many cases, it's quicker and easier to select a value from a list than to remember a value to type. A list of choices also helps to ensure that the value that's entered in a field is correct. If you have enough room on your form or data access page to display the list at all times, you might want to use a list box. When you want to create a control that displays a list but requires less room, use a combo box if you are working in a form, or use a drop-down list box if you are working in a data access page.
List boxes The list in a list box consists of rows of data. In a form, a list box can have one or more columns, which can appear with or without headings. If a multiple-column list box is bound, Access stores the values from one of the columns. In a data access page, a list box has one column without a heading.
When you click a value in a list box...
...if the list box is bound, Access inserts the value selected into the field that the list box is bound to. If the bound column is different from the column displayed in the list, Access inserts the value from the bound column instead of the value you clicked.
This is the underlying record source that the form is bound to.
You can use an unbound list box to store a value that you can use with another control. For example, you could use an unbound list box to limit the values in another list box or in a custom dialog box. You could also use an unbound list box to find a record based on the value you select in the list box.
Combo boxes A combo box is like a text box and a list box combined, so it requires less room. You can type new values in it, as well as select values from a list. The list in a combo box consists of rows of data. Rows can have one or more columns, which can appear with or without headings.
Type text directly into a combo box...
...or click the arrow...
...to see a list of values to choose from.
When you enter text or select a value in a bound combo box, the entered or selected value is inserted into the field that the combo box is bound to. If a multiple-column combo box is bound, Access stores only the value from the bound column. You can use an unbound combo box to store a value that you can use with another control. For example, you could use an unbound combo box to limit the values in another combo box or in a custom dialog box. You could also use an unbound combo box to find a record based on the value you select in the combo box.
Drop-down list boxes On a data access page, you can use a drop-down list box instead of a list box. A drop-down list box on a data access page looks like a combo box on a form. As in a combo box, a drop-down list box shows only one record until you click to expand the contents; however, you can't type new values in a drop-down list box. The list in a drop-down list box consists of rows of data. Rows can have only one column that appears without headings.
Click the arrow...
...to see a list of values to choose from.
When you select a value in a drop-down list box that is bound to a field, the selected value is inserted into that field. You can also use an unbound drop-down list box to store a value that you can use with another control. For example, you could use an unbound drop-down list box to limit the values in another drop-down list box. You could also use an unbound drop-down list box to find a record based on the value you select in the drop-down list box.
Command buttons provide you with a way of performing action(s) by simply clicking them. When you choose the button, it not only carries out the appropriate action, it also looks as if it's being pushed in and released.
You use a command button on a form or data access page to start an action or a set of actions. For example, you can create a command button that opens another form. To make a command button do something on a form, you write a macro or event procedure and attach it to the button's OnClick property. On a data access page, you can attach code written in either Microsoft JScript or Microsoft Visual Basic Scripting Edition (VBScript) to a command button by using the Microsoft Script Editor.
You can display text or a picture on a command button in a form; you can display only text on a command button in a data access page.
You can create a command button on your own, or you can have Microsoft Access create your command button for you by using a wizard. A wizard speeds up the process of creating a command button because it does all the basic work for you. When you use a wizard, Access prompts you for information and then creates the command button based on your answers. By using the wizard, you can create more than 30 different types of command buttons. You can create command buttons to:
- Dial a phone number.
- Run a query or macro.
- Run or quit an application.
- Edit or apply a filter.
- Print or mail a report.
- Print the current record.
- Update form data.
- Find a specific record.
It's also a good idea to use the Command Button Wizard if you want to learn how to write event procedures. When Access creates a command button in a form or report with a wizard, it creates an event procedure and attaches it to the button. You can open the event procedure to see how it works and modify it to fit your needs. When you create a command button on a data access page with a wizard, Access doesn't create event procedures for you.
Wizards are not available in a stand-alone data access page or when you point a data access page to a database other than the one currently open. The Command Button Wizard is also not available if a data access page isn't bound to a table or query. You will have to create a command button on your own if wizards aren't available.
You can use a check box on a form, report, or data access page as a stand-alone control to display a Yes/No value from an underlying table, query, or SQL statement. For example, the check box in the following illustration is bound to the Discontinued field in the Products table. The data type of the Discontinued field is Yes/No. If the box contains a check mark, the value is Yes; if it doesn't, the value is No.
This stand-alone check box is bound to the Discontinued field in the Products table.
When you select or clear a check box that's bound to a Yes/No field in a Microsoft Access database or a Bit column in an Access project, Access displays the value in the underlying table according to the field's Format property (Yes/No, True/False, or On/Off). In an Access project, the option button is bound to a column defined as a Bit data type. When the value in this column is 1, it is equivalent to Yes, On, or True conditions. When the value is 0, the column indicates No, Off, or False conditions.
You can use check boxes in an option group to display values to choose from.
You can use an option button on a form, report, or data access page as a stand-alone control to display a Yes/No value from an underlying record source. For example, the option button in the following illustration is bound to the Discontinued field in the Products table of a database. The data type of the Discontinued field is Yes/No. If the option button is selected, the value is Yes; if not, the value is No.
This stand-alone option button is bound to the Discontinued field in the Products table. The value in the field is Yes.
When you select or clear an option button that's bound to a Yes/No field in a Microsoft Access database, the value in the underlying table displays according to the field's Format property (Yes/No, True/False, or On/Off). In a Microsoft Access project, the option button is bound to a column defined as a Bit data type. When the value in this column is 1, it is equivalent to Yes, On, or True conditions. When the value is 0, the column indicates No, Off, or False conditions. You can also use option buttons in an option group to display values to choose from.
You can use an option group on a form, report, or data access page to display a limited set of alternatives. An option group makes selecting a value easy because you can just click the value that you want. Only one option in an option group can be selected at a time. If you want to present more than a few options, use a list box, a combo box, or a drop-down list box instead of an option group.
In a form or report, an option group consists of a group frame as well as a set of check boxes, option buttons, or toggle buttons. In a data access page, an option group consists of a group frame and a set of option buttons.
Label
The option group is the frame that surrounds the controls inside it.
Option buttons
Only one option in an option group can be selected at a time.
If an option group is bound to a field, only the group frame itself is bound
OptionValue property set to 1; when you click this button, Access sets the value of the Ship Via option group to 1 and stores this number in the underlying table.
OptionValue property set to 2
OptionValue property set to 3
Notes
- The OptionValue or Value property is set to a number because the value of an option group can only be a number, not text. Access stores this number in the underlying table. In this example, if you want to display the name of the shipper instead of a number in the Orders table in an Access database, you can create a separate table called Shippers that stores shipper names, and then make the ShipVia field in the Orders table a Lookup field that looks up data in the Shippers table.
- In a form or report, an option group can also be set to an expression.
You can use a toggle button on a form as a stand-alone control to display a Yes/No value from an underlying record source. For example, the toggle button in the following illustration is bound to the Discontinued field in the Products table of a database. The data type of the Discontinued field is Yes/No. When the button is pressed in, the value in the Products table is Yes. When the button isn't pressed in, the value in the Products table is No.
This stand-alone toggle button is bound to the Discontinued field in the Products table. The button is pressed in, so the value in the field is Yes.
When you click a toggle button that's bound to a Yes/No field in a Microsoft Access database, the value in the underlying table displays according to the field's Format property (Yes/No, True/False, or On/Off). In an Access project, the option button is bound to a column defined as a Bit data type. When the value in this column is 1, it is equivalent to Yes, On or True conditions. When the value is 0, the column indicates No, Off, or False conditions.
Toggle buttons are most useful when used in an option group with other buttons. In an option group, you can easily tell whether a button is pressed in.
Also, you can use pictures on toggle buttons instead of text. For example, instead of displaying the word "Discontinued" on the toggle button in the first example, you could display a picture of a trash can.
You can use a tab control to present several pages of information as a single set. This is especially useful when you're working with many controls that can be sorted into two or more categories. For example, you might use a tab control on an Employees form to separate employment history and personal information.
Information about employment history is displayed on this page.
Personal information, such as home address and phone number, is displayed on this page.
Additional controls that you can use on data access pages
You can store HTML code in a field in a table, and when the data access page displays the values in that field, the HTML code performs the actions that you specified. You can accomplish this by binding the bound span control to a Text or Memo field in a Microsoft Access database or a text, ntext, varchar, or any other column that can store text in a Microsoft Access project. The contents of a bound span control are not editable.
For example, if a value in a field is <font color=red>red Text</font> and you set the DataFormatAs property to HTML, you will see red text when you view the data access page in Page view. If the DataFormatAs property is set to Text, then <font color=red>red Text</font> is the value displayed in the control. The default value of the DataFormatAs property is Text.
If the HTML text is lengthy, bind the bound span control to a field with the Memo data type (Access database), or the text or ntext data type (Access project).
Notes
- You can make the bound span control the default control for a grouped data access page. Set the DefaultControlType property of the data access page to Bound Span.
- You can use a bound span control to display calculations and data on a grouped data access page. In Microsoft Internet Explorer 5.01 with Service Pack 2 (SP2) or later, bound span controls load faster than other controls, and hence improve the performance of the page.
- The bound HTML control in Access 2000 has been replaced by the bound span control in Access 2002 and later. Bound HTML controls on pages created using Access 2000 will automatically convert to bound span controls when you open the page in Access 2002 or later.
Security Use bound span controls or hyperlink controls with caution. Unauthorized users may be able to insert harmful HTML text into these controls. Processing this text without validation or modification could result in the loss of personal information or other data. To prevent the HTML text contained in a control from being rendered, encode the contents of the control.
Use the hyperlink control when each record in the underlying record source has a different hyperlink address. You bind the hyperlink control to a Text field that contains hyperlink values, such as e-mail addresses.
As you move from record to record in Page view or Microsoft Internet Explorer, you can click the hyperlink to either go to a different Web page or open a mail program to send an e-mail message.
Security Use bound span controls or hyperlink controls with caution. Unauthorized users may be able to insert harmful HTML text into these controls. Processing this text without validation or modification could result in the loss of personal information or other data. To prevent the HTML text contained in a control from being rendered, encode the contents of the control.
Use the image hyperlink control to add an image to a data access page that, when clicked, displays another Web page from your hard drive, the Web, or another location. When you create an image hyperlink control, you select the image to display on the page and the address of the file to jump to. In Page view, as the pointer passes over the image, the pointer changes to a hand, indicating that the image is a link that you can click to go to another page. You can also define ScreenTips and alternate text for the image.
The image hyperlink control is useful for providing links to information that relates to data on your data access page.
Use a scrolling text control, often called a marquee, on a data access page to display moving text or text that scrolls. Scrolling text draws attention to a line of text, such as a headline or an important announcement. You display text that is contained in a field of your database by binding the scrolling text control to the field. You can customize scrolling text by setting options such as direction of travel, speed, and type of motion.
The text does not scroll in Design view. To see the scrolling text, you have to open the page that contains the control in Page view or in Microsoft Internet Explorer.