Insert a button
Some of the content in this topic may not be applicable to some languages.
You can insert a button, sometimes referred to as a command button or push button, on a Microsoft Office InfoPath form template. Users click buttons to initiate an immediate action, such as submitting a form to a Web service or querying a database. You can associate a button with rules or custom code that runs when a user clicks the button.
In this article
When to use a button
Buttons are versatile controls that are useful in many different scenarios. For example, you can use a button when you want to:
-
Submit data to one or more data sources.
-
Enable users to switch to another view of the form.
-
Refresh data from a secondary data source.
-
Clear any queried data from the form.
-
Calculate data on the form.
If you know how to write code, you can use a button to perform more sophisticated actions or to do things that are not supported in the user interface in design mode. For example, you can use code to automatically delete all the rows in a repeating table when a user clicks a Delete All button.
If you design your form template so that it submits data to a database or other external data source, then a Submit command on the File menu and a Submit toolbar button will be added to the form. However, those submission points are easy for users to miss. Therefore, you may want to consider adding a Submit button to your form template. The following illustration shows how that might look on a user's form.
When you add a button to your form template, by default, InfoPath inserts a button with "Button" as the text that appears on the control. If you want to change the text and assign an action to the button by using a rule, you must double-click the button and specify options in the Button Properties dialog box.
If you want the text on the button to change depending on values on the form, you can create a dynamic button label. For example, you can create a button with the label Send To Manager, where Manager is the name that a user types in a Manager text box elsewhere on the form.
Insert a button
The procedure for inserting a button is the same whether you are designing a new, blank form template or basing the design of your form template on a database or other external data source.
The following illustration shows how a button looks when it is selected in design mode.
Unlike most other InfoPath controls, buttons are not bound to fields or groups in the data source. This is because they are used to initiate an action, not to collect data from the user.
Insert a button
-
On the form template, place the cursor where you want to insert the control.
-
If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.
-
Under Insert controls, click Button.
-
Double-click the button icon that was inserted onto your form template.
-
Click the General tab.
-
In the Action list, click the action that you want the button to perform.
Available actions
The Submit and Rules and Custom Code actions are always available. The availability of other button actions depends on how the form template was designed and whether the form template includes a data connection that queries or submits data to external data sources, such as a database or Web service.
Action
Description
Submit
This action initiates the standard submit functionality for the form — this is the same as the user clicking Submit on the File menu. To initiate a custom submit action, select Rules and Custom Code, and then create a rule for submitting the data.
Rules and Custom Code
This action either runs a rule when the button is clicked or runs custom code. For example, you can create a rule that automatically submits the data from a form to a Web service or submits the data as an e-mail message, in response to the user clicking the button. To define a rule, click Rules. To define code, click Edit Form Code.
Run Query
If the form is connected to a database or Web service, this action queries a database or Web service based on the values entered in the fields that are used to query the data.
New Record
If the form is connected to a database or Web service, this action clears the values on the form so that a user can enter new data.
Delete & Submit
If the form is connected to a database or Web service, this action deletes the records from the database that have been returned in a query.
Refresh
If the form is connected to a database or Web service, this action refreshes the data from the database or Web service that has been returned in a query.
Update Form
In a form that is designed to be filled out in a Web browser, this action updates form data in an incremental manner. For example, imagine a Total box that changes based on the values that users enter in other controls on the form. To avoid refreshing the form whenever the values in those controls change, you can prevent data from being sent to the server for those specific controls. You can then add an Update Totals button next to the Total box, which the user can click to manually refresh the totals. The button associated with the Update Form action is visible only when users display and fill out the form in the browser.
-
In the Label box, do one of the following:
-
To use custom text on the button, type the text that you want to display.
-
To use a value from the form for the button text, click Insert Formula . In the Insert Formula dialog box, click Insert Field or Group, and then select the field or group that you want to use.
-
Layout tips
Use the following tips to help you refine the appearance, size, and other aspects of a button control:
-
Buttons tend to look best when their labels are only a few words long.
-
To change the size of several buttons at once, select the buttons whose size you want to change. Press ALT+ENTER, and then make the necessary adjustments on the Size tab.
-
To change the border or color of a button, select the button that you want to change. On the Format menu, click Borders and Shading, and then make the necessary adjustments.
-
It is not possible to add an image to a button in design mode. To work around this limitation, you can manually edit the manifest (.xsf) file that is associated with the form template, although this method is recommended only for advanced form designers.
-
If you use the same button in more than one view, try to place it in a similar location in each view and use the same button text for consistency.
-
For a more polished look, consider limiting the number of different widths you use for the buttons in your form template. Also, try to avoid using narrow, short, or tall buttons, because non-standard button sizes often look unprofessional.
No comments:
Post a Comment