Display the contents of two fields in one control
You can use expression boxes to display the contents of two fields in one control (or concatenate two fields), as well as perform other calculations. When you create formulas in an expression box, you refer to the fields and groups to which controls on the form are bound, rather than the controls themselves. The formulas are created using XPath, but you can follow these steps without knowing XPath.
- In design mode, place the insertion point where you want to insert the expression box.
- If the Controls task pane is not visible, click More Controls on the Insert menu.
- In the Controls task pane, click Expression Box.
- Enter an expression such as one of the following in the XPath box in the Insert Expression Box dialog box:
Expression type Expression Display two fields separated by a space concat(my:field1, " ", my:field2) Display two fields separated by a comma concat(my:field1, ",", my:field2) Display two fields run together concat(my:field1, my:field2) In the preceding table, my:field1 and my:field2 are only examples. When you type your concatenation expression, you must replace the examples with XPath expressions that identify your specific fields. In addition, you can change the text that separates the two fields.
- In the Insert Expression Box dialog box, click Select XPath
.
- In the Select a Field or Group dialog box, select the first field that you want, and then click OK.
- In the Insert Expression Box dialog box, select the expression in the XPath box and copy it.
- In a text editor such as Microsoft Notepad, type concat(
- After the text in the text editor, paste the expression you copied.
- After the expression in the text editor, do one of the following:
- To display a space between the two fields, type ," ",
- To display a comma between the two fields, type ,",",
- To display the two fields as run together, type ,
- In the Insert Expression Box dialog box, click Select XPath
again.
- In the Select a Field or Group dialog box, select the second field that you want, and then click OK.
- Select the expression in the XPath box and copy and paste it into the text editor, after the existing text.
- In the text editor, select the entire expression, and then copy and paste it into the XPath box in the Insert Expression Box dialog box.
- After the expression in the XPath box, type )
- In the Insert Expression Box dialog box, click Select XPath
- To test the formula, click Preview Form on the Standard toolbar.