Ryan Anderson wrote:
I want to program a button in infopath 2007 so that when i click on it, it will refresh all fields back to original format.
Hello Ryan,
Thank you for your question. With “refresh all fields back to original format” I’m assuming you mean “reset or restore the original data that the fields contained”? If you meant something else, please post a comment and correct me if I’m wrong.
InfoPath does not have a Reset button, so you will have to create one yourself. There are basically two ways to do this: 1. Without code and 2. With code.
Option 1: Without code
You can add a button to a form template and then create a Rule with one or more Actions that will set the values of the fields that you want to reset to the desired data.
Option 2: With code
You can add a button to a form template and then write code to set the value of each field that you want to reset to the desired data. For code on how to programmatically set the value of a field, see http://www.bizsupportonline.net/infopath2007/infopath-2007-frequently-asked-questions-faq.htm#how-to-set-field-value-from-code.
If you have many fields on your form template, which you want to reset, it will be a lot of work to create an Action to set the value of each field if you use option 1.
If you use option 2, you could potentially write code to loop through all the fields in a form and then set the value of them, but you will have to device a way to
- Know which field you are setting
- Know which value to set a field to
You could for example use an XML file to define the the default value that corresponds to each field (using the field’s name), add this XML file as a secondary data source to your InfoPath form template, and then while looping through all the fields of your form, perform a lookup in the secondary data source of the XML file and set the field’s value accordingly. For more information on programming in InfoPath 2007, see Working with XML Data Using the XPathNavigator Class in InfoPath 2007 Form Templates.
I hope this answers your question, Ryan.

Comments to this post were closed 30 days after it was published.