7.1. Using Expression Boxes with Formulas

Before you jump into the more complicated controls, there is a control that displays formulas on your InfoPath forms. Besides being able to bind text boxes to fields, as is done when you drag fields from the data source, you can display formulas using a control called an expression box.

Creating a formula to display in an expression box is the same as creating a formula for a default value except that you can use other fields within the formula. You can use formulas in a number of ways. Following are two of the most common:

  • Totaling columns: InfoPath supplies built in functions such as sum(), avg(), and others.

  • Combining the values of multiple fields.

In this section, you get a chance to work with multiple fields.

Once you have added an expression box, you need to specify the formatting of the data being displayed. To do this, you open the property sheet of the expression box control and set the format.

7.1.1.

7.1.1.1. Try It Out: Adding an Expression Box Based on a Formula

Once you open the form called Chapter 7 Intro.xsn in Design mode, you can see, as in Figure 7-1, that there is a column with the title of Item Total. The object of this Try It Out is to add an expression box to display a total for each item.

Figure 7.1. Figure 7-1

  1. Place the cursor in the table cell beneath the Item Total label.

  2. Click on the Controls task in the Design tools task pane. The Controls task pane is then displayed.

  3. Click on the Expression Box control under the Advanced controls. The Insert Expression Box dialog box is opened, as shown in Figure 7-2.

    Figure 7.2. Figure 7-2
  4. At this point, you can either fill in the expression if you are comfortable or you can click on the Formula button, as shown in Chapter 6, "Working with Controls in General." If you click on the Formula button, the Insert Formula dialog box opens.

  5. Using the steps discussed in Chapter 6, in the section titled "Using Formulas," you can create the following formula in the Insert Formula dialog box displayed here in Figure 7-3.

  6. Click Verify Formula to verify the formula.

  7. Click OK to accept the formula. The Insert Formula dialog box closes.

    Figure 7.3. Figure 7-3
  8. Click OK to accept the expression box. The expression box is then added to the form. It's time now to set the format of the expression box. In this case, you will be setting the format of the control to the Currency format.

  9. Open the property sheet of the new expression box.

  10. Select Decimal for the Format as: property.

  11. Click the Format button. The Decimal Format dialog box opens.

  12. Click the Currency option, as shown in Figure 7-4.

    Figure 7.4. Figure 7-4
  13. Click OK twice to accept the formatting. You are now ready to test the form.

  14. Click Preview Form, type BC for the Region, and click Run Query. You will then see the new expression box on the form, as shown in Figure 7-5.

And there you have it. The Item Total column is displayed with the discount being taken into effect.

Figure 7.5. Figure 7-5

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.105.89