Create a text box

Microsoft Office Access 2003

Before creating a bound control, make sure that your form or report is bound to a record source, or that your data access page is connected to a database.

  1. Open a form, report, or data access page in Design view.
  2. If the field list isn't visible, click Field List Button image on the toolbar.
  3. Click the Text Box tool Button image in the toolbox.
  4. Do one of the following:

    Select one or more fields in the field list on a form or report.

    To select Do this
    One field Click the field.
    A block of fields Click the first field in the block, hold down the SHIFT key, and then click the last field in the block.
    Nonadjacent fields Hold down the CTRL key and click the name of each field that you want to include.

    Select a field, table, or query in the field list on a data access page.

    To select Do this
    One field Click the field.
    A table or query Click the Wizard tool Button image in the toolbox if it's not already selected, and then click the table or query.
  5. Do one of the following:
    • Drag the field or fields from the field list and position them on the form or report.
    • Drag the field, table, or query from the field list and position it on the data access page. If you are dragging a table or query, click the layout you want in the Layout Wizard dialog box.

    Note Microsoft Access won't create the control if you try to add it by clicking the form, report, or data access page instead of dragging the selected field from the field list.

    Access places one text box on the form, report, or data access page for each field that you select in the field list. Each text box is bound to one field in the underlying data source. Each text box also has an attached label by default.

  6. Size the text box so that it's the appropriate size for the data you want to show.
  7. Change the label text if necessary.
  8. Switch to Form view, Datasheet view, Page view, or Print Preview to test the control.

Note  If the data in a text box on a form contains many lines of text, you might want to set the ScrollBars property to Vertical.

ShowCreate an unbound text box

  1. Open a form, report, or data access page in Design view.
  2. Click the Text Box tool Button image in the toolbox.
  3. Click anywhere on the form, report, or data access page to create a default-sized text box, or drag to create a text box that's the size you want.

ShowCreate a calculated text box

ShowIn a form or report

  1. Open a form or report in Design view.
  2. Click the Text Box tool Button image in the toolbox.
  3. In the detail section, click where you want to place the text box.
  4. Do one of the following:

    Place the insertion point in the text box and type an expression that calculates a total.

    Select the text box, click Properties Button image on the toolbar, and type the expression in the ControlSource property box. In a Microsoft Access database (.mdb), to use the Expression Builder to create the expression, click the Build button Button image next to the ControlSource property box.

Notes

  • If you need more room to type an expression in the ControlSource property box, press SHIFT+F2 to open the Zoom box.
  • If a form or report is based on a query, you may want to put the expression in the query instead of in a calculated control. It may improve performance, and if you are going to calculate totals for groups of records, it's easier to use the name of a calculated field in an aggregate function.

ShowIn a data access page

If you want to do complex calculations using spreadsheet functions, use the Microsoft Office Spreadsheet Component. For all other calculations, you can use the bound span control.

ShowUsing the Spreadsheet Component

  1. Open the data access page in Design view.
  2. If they aren't already on the page, add the controls that will contain the data you want to use in the calculation.
  3. Click the Office Spreadsheet tool Office Spreadsheet control in the toolbox, and then click where you want the upper-left corner of the spreadsheet to be on the data access page.
  4. In any cell in the spreadsheet, enter a formula that uses the HTML Host function to refer to the fields used in the calculation, and the specific operation you want to perform on the field's values expressed as a combination of operators, identifiers, and values.

    Example    To multiply the value in the Quantity field by the value in the UnitPrice field, type:

    =Host().Quantity.value*Host().UnitPrice.value

    Example    To multiply the value in the UnitPrice field by a percentage rate stored in cell C1, type:

    =$C$1*Host().UnitPrice.value

Notes

  • To see the name of a spreadsheet, select the control, and then click Properties Button image on the toolbar. The property sheet title bar displays the spreadsheet name.
  • You can use spreadsheet functions, which, in Microsoft Access, are available only in this control.
  • Most likely, you'll want the calculated value to display in an area that looks like the other controls on the data access page. To do this you can modify the appearance of the spreadsheet so it looks like a text box.

ShowUsing the bound span control

  1. Open the data access page in Design view.
  2. If the expression will reference field names, the fields must be in the page's data definition. Either add the fields to the page as bound span controls, or add the fields as bound text boxes.

    ShowTip

    The page will load faster in Page view and in Microsoft Internet Explorer if you use bound span controls.

    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.

  3. Create another control by clicking the Bound Span tool Bound HTML control or the Text Box tool Button image in the toolbox, and then click where you want the upper-left corner of the control to be on the page.

  4. To display the property sheet, make sure that the control is selected, and then click Properties Button image on the toolbar.
  5. In the ControlSource property box, type an alias and an appropriate expression. To reference fields on the page, use the names of the fields in the expression. For example, if you want to compute the extended price for a record in the Order Details table, type:

    ExtendedPrice: UnitPrice*Quantity

    If you don't specify an alias, you must type an equal sign (=) before the expression. Microsoft Access will automatically supply an alias— for example, Expr1.