Add a text box control to a form or report

The text box is the standard control used for viewing and editing data on forms and reports. Many different types of data can be displayed in text boxes, and you can also use them to perform calculations. This article explains how to create and use a text box and also explains some important text box properties.

What do you want to do?


Add a bound text box

A bound text box displays data from a field in a table or query. On a form, you can use a text box that is bound to an updatable record source to enter or edit data in a field. The changes that you make in the text box will be reflected in the underlying table.

A quick way to create a bound text box is by dragging a field from the Field List pane onto your form or report. Access automatically creates a text box for fields of the following data types:

  • Text
  • Memo
  • Number
  • Date/Time
  • Currency
  • Hyperlink

Dragging fields of other data types creates different types of controls. For example, if you drag a Yes/No field from the Field List pane to a form or report, Access creates a check box. If you drag an OLE Object field to a form or report, Access creates a bound object frame, and if you drag an attachment field to a form or report, Access creates an attachment control.

Add a bound text box to a form or report by dragging a field from the Field List pane

  1. Open the form or report in Layout view or Design view by right-clicking the form or report in the Navigation Pane, and then clicking the view you want.
  2. On the Format tab, in the Controls group, click Add Existing Fields Button image.
  1. In the Field List pane, expand the table containing the field that you want to be bound to your text box.
  2. Drag the field from the Field List pane to the report or form.

For more information about working with the Field List pane, see the article Add a field to a form or report.

You can also add a bound text box to a form or report by first adding an unbound text box, and then setting the Control Source property of the text box to the field you want to bind it to.

Top of Page Top of Page

Add an unbound text box

An unbound text box is not connected to a field in a table or query. You can use an unbound text box to display the results of a calculation or to accept input that you don't want to store directly in a table. It is easiest to add an unbound text box in Design view.

  1. Open the form or report in Design view by right-clicking the form or report in the Navigation Pane, and then clicking Design View.
  2. On the Design tab, in the Controls group, click Text Box. Button image
  1. Position the pointer where you want the text box to be placed on the form or report, and then click to insert the text box.

 Note    Access also places a label to the left of the text box, so leave some room to the left of the pointer for the label. You can reposition the label and the text box later. You can also delete the label by clicking it and then pressing DELETE.

Another way to create an unbound text box is by first creating a bound text box by dragging a field from the Field List pane onto the form or report, and then deleting the value in its Control Source property. If you do this in Design view, the text box will display "Unbound" instead of the field name. In Layout view, the text box will no longer display data — in fact, it will be blank.

Top of Page Top of Page

Add a calculated text box

  1. Open the form or report in Design view by right-clicking the form or report in the Navigation Pane, and then clicking Design View.
  2. On the Design tab, in the Controls group, click Text Box. Button image
  1. Position the pointer where you want the text box to be placed on the form or report, and then click to insert the text box.
  2. Do one of the following:

Place the cursor in the text box, and then type an expression (expression: Any combination of mathematical or logical operators, constants, functions, and names of fields, controls, and properties that evaluates to a single value. Expressions can perform calculations, manipulate characters, or test data.) that calculates a total.

Select the text box, press F4 to display the property sheet, and type the expression in the Control Source property box. To use the Expression Builder (Expression Builder: An Access tool that you can use to create an expression. It includes a list of common expressions that you can select.) to create the expression, click Button image next to the Control Source property box.

  1. Save the form or report and then switch to Form view or Report view to check the results.

For more information about creating expressions, see the article Create an expression.

 Notes 

Top of Page Top of Page

Understand text box properties

Regardless of how you create a text box, certain properties need to be set so that the text box works and appears the way that you want. The following list shows a few of the more important and commonly used text box properties:

  • Name    You should give your text box a short, meaningful name so that you can easily tell what data it contains. This makes it easy to refer to the text box in expressions that you might use in other text boxes. Some database developers prefer to add a prefix, such as txt, to text box names so that they can easily distinguish text boxes from other types of controls. — for example, txtFirstName or txtAddress.

When you create a bound text box by dragging a field from the Field List pane, Access uses the field name as the text box name. This usually works well, but if you plan to edit the Control Source property and create an expression, it is a good idea to first change the text box name so that it is different from the field name. Otherwise, Access might be unable to determine whether you are referring to the text box or to the field in the table. For example, suppose you have a report containing a text box named First Name, which is bound to a table field named First Name. If you want to trim any spaces that might precede the value in the First Name field, you might set the Control Source property of the text box to:

=Trim([First Name])

However, this results in #Error appearing in the text box, because Access cannot determine whether the expression is referring to the field or to the text box. To fix this problem, rename the text boxes so that they have unique names.

  • Control Source    This property determines whether the text box is bound, unbound, or calculated.
    • If the value in the Control Source property box is the name of a field in a table, the text box is bound to that field.
    • If the value in Control Source is blank, the text box is unbound.
    • If the value in Control Source is an expression, the text box is a calculated text box.
  • Text Format    If the text box is bound to a Memo field, you can set the value in the Text Format property box to Rich Text. Doing this allows you to apply multiple formatting styles to the text contained in the text box. For example, you can apply bold formatting to one word and underlining to another.
  • Can Grow    This property is particularly helpful on reports for text boxes that are bound to Text or Memo fields. The default setting is No. If there is too much text to display in the text box, the text is truncated (cut off). However, if you set the value of the Can Grow property box to Yes, the text box automatically adjusts its vertical size to print or preview all the data that it contains.

 Tip    Try Office 2010 Access 2010 includes new conditional formatting features that can greatly improve the readability of a report. Watch a video or try Office 2010!

Top of Page Top of Page

 
 
Applies to:
Access 2007