Section 11.5. Expressions

11.5. Expressions

Earlier in this chapter, you learned how to add a label and set its text. But if you look at the controls on a typical report, you'll quickly notice that they don't all use ordinary text. Consider the date or page number information (which appears in the top-right corner of a simple report). Both these details appear in ordinary label controls, but the text looks distinctly different. It starts with an equal (=) sign, which indicates the presence of an expression .

Expressions let labels and other controls show dynamic values. No one wants to type in a specific date in a report, because you'd be forced to update it every time you want to make a printout. Instead, you use an expression like =Date() , which tells Access to grab the current date from the computer clock and display that.

Expressions aren't new. You learned about them with queries in Chapter 6 (Section 7.1). However, until now you probably didn't realize that they're equally at home in reports . You can add your own expressions to a report to display dynamic data, or perform calculations based on other fields.

Suppose you want to improve the wedding list by combining the first and last names into a compact one-line display. As you learned in Section 7.1.3, the & symbol's the ticket for fusing together pieces of text. Here's the expression you need:

 =FirstName & " " & LastName 

Tip: Refer to Chapter 7 (starting in Section 7.1) for an overview of expressions, the different types of calculations you can perform, and the different functions you can use with them.

You can't enter an expression into a label control, because a label's limited to fixed, unchanging text. Instead, you need to use the text box control. (Access also uses the text box control to display most fields.)

Once you've added the text box to the design surface, click to select it. The mouse pointer changes into the text pointer. Click again to edit the text, and then enter your expression exactly, remembering to start with the equal sign (Figure 11-17).

Figure 11-17. Top: The expression looks like an ordinary text value in Design view.
Bottom: When you preview the report, Access performs the calculation, and then shows the result.

Access 2007[c] The Missing Manual
Access 2007[c] The Missing Manual
ISBN: 596527608
Year: 2007
Pages: 153 © 2008-2017.
If you may any questions please contact us: