InfoPath Solutions Blog

Blog about InfoPath and related technologies such as SharePoint, .NET, and other Microsoft software products.

Display the same repeating table in different places in InfoPath

Published on Tuesday, 16 March 2010 by S.Y.M. Wong-A-Ton

There might be times when you would like to enter data in a repeating table on an InfoPath form, and then take this data and display it in another repeating table either on the same View or a different View.

I’ve previously created an InfoPath video tutorial that explains how to work with Views in InfoPath.

A View is not only a canvas on which you place controls, but you can also see it as a window into the data source of an InfoPath form template.

This means that you can have multiple controls, which include repeating tables, on a View pointing to the same data in the data source of an InfoPath form template.

If you bind multiple repeating tables that are located on the same View to the same nodes in the data source, InfoPath will display an icon indicating that the fields in the repeating tables are referring to the same data. This is not an error, it is just for informational purposes (see Figure 1).

Repeating table fields displaying duplicate data in InfoPath
Figure 1. Repeating table fields displaying duplicate data in InfoPath.

To display the same data in a repeating table on different places on an InfoPath form:

  1. From the Controls task pane, add a Repeating Table to your InfoPath form template.
  2. From the Data Source task pane, drag the repeating node of the repeating table you just added, drop it on the InfoPath form template, and select Repeating Table from the context menu that appears. Alternatively, you could create a second View, and repeat this step to add a repeating table that contains the same data as the repeating table of step 1 to your InfoPath form template

Your InfoPath form should now display the same data in multiple repeating tables on the form, and when you enter data in one repeating table, the same data will appear in the other repeating table on the InfoPath form.

How to open an InfoPath form and template that were moved or copied

Published on Wednesday, 10 March 2010 by S.Y.M. Wong-A-Ton

Problem

Your client had an InfoPath developer (someone you do not know) build an InfoPath form template and then publish it to a SharePoint server at your client’s site.

You do not have access to the SharePoint server where the form template was published, neither do you have direct access to the InfoPath form template the other person created and deployed to SharePoint.

To keep this scenario simple, let’s assume that the InfoPath developer did not add code to the InfoPath form template, so you’re dealing with a codeless InfoPath form template that was deployed to a SharePoint Form Library.

The InfoPath form template is not doing exactly what your client wants it to do, and the InfoPath developer has since left the company.

Now your client wants you to take a look at the form template and troubleshoot the form template and an XML file that was created using that form template, so your client sends you both the XML file and the original InfoPath form template that was deployed to SharePoint.

Now when you try to open the InfoPath form, you get the following error message:

InfoPath cannot open the following file: <InfoPath_Form_File_Name_And_Path>.
The following form template for the form cannot be found:

http://<SharePoint_Server_Name>/<SharePoint_Site_Name>/<SharePoint_Form_Library_Name>/forms/template.xsn

And when you try to open the InfoPath form template in Design mode, you get the following warning:

The form template was published to one location and has been saved or moved to a different location. To ensure that forms based on this template work correctly, publish the template again.

Solution

I’ve briefly touched upon how InfoPath form templates and InfoPath forms are related in the video tutorial Creating a simple InfoPath form template, but I’ll recap the essence of the story here.

An InfoPath form is an XML file that is based on an InfoPath form template (an XSN file). The XSN file contains all of the code and logic for an InfoPath form to be filled out through either the InfoPath client application or through a browser via SharePoint.

This means that the two always go together: To open an InfoPath form, you always have to have an InfoPath form template published somewhere. In essence, an InfoPath form is linked to its corresponding InfoPath form template.

But because an InfoPath form is just an XML file (so a text file), you can open it in Notepad to relink it to a different InfoPath form template that has the same structure and version as the original form template from which it was created.

So to fix the problem described above, you must do two things:

  1. Save the form template to your own computer (so that you can troubleshoot it) from within the InfoPath client application.
  2. Change the InfoPath form to point to the template you saved on your own computer.

Fixing InfoPath form templates that have been copied or moved

When an InfoPath form template has been moved or if you receive one that was saved or published to a different location than where it is currently located, all you have to do is open it, save it, and then republish it.

To correct an XSN (InfoPath form template) that has been moved or copied:

  1. In Windows File Explorer, right-click the InfoPath form template (XSN), and choose Design from the context menu that appears.
  2. When the InfoPath form template opens in InfoPath, click OK to close the warning message.
  3. On the File menu, click Save As, and save the InfoPath form template locally somewhere on disk.

The XSN should now open without any warnings, and you should be able to publish it.

Fixing forms that are linked to templates that have been moved

When an InfoPath form template that an InfoPath form is linked to is moved or cannot be found, you have to relink the InfoPath form to point to the InfoPath form template that has been published to a new location.

To relink an InfoPath form to an InfoPath form template that was moved and republished:

  1. Open the InfoPath form in Notepad.
  2. Change the href attribute in the mso-infoPathSolution processing instruction to point to the correct location for the newly published InfoPath form template.

    InfoPath form processing instruction with the InfoPath form template the InfoPath form is linked to highlighted in yellow and the version number highlighted in green

    Figure 1. InfoPath form processing instruction with the InfoPath form template the InfoPath form is linked to highlighted in yellow and the version number highlighted in green.

  3. If the version number of the newly published InfoPath form template differs from the original InfoPath form template of the InfoPath form, change the solutionVersion attribute to be the same as the newly published InfoPath form template.

You should now be able to open the InfoPath form without any warnings or errors.

Note:
Every time you save or publish an InfoPath form template, its version number is automatically increased.

InfoPath form template version number on the Form Options dialog box

Figure 2. InfoPath form template version number on the Form Options dialog box.

If you link an InfoPath form to an InfoPath form template that is of a newer version than the template the InfoPath form was originally created from, you’ll get the following warning message:

This form was created with a new version of the form template. InfoPath cannot find the new version. Do you want to open with the older version?

How to set the maximum field length in InfoPath

Published on Monday, 1 March 2010 by S.Y.M. Wong-A-Ton

If you’re used to programming in Visual Studio, you’ll be disappointed to know that there is no MaxLength property that you can set on fields in InfoPath that can hold multiple lines of text with line breaks.

So if you want to set the maximum field length on a multi-line InfoPath Text Box (that allows line breaks) or Rich Text Box, you must use data validation.

Note: You can limit the amount of characters on a single-line text box by going to the Properties dialog box of the text box, clicking on the Display tab, and selecting the Limit text box to checkbox.

When using data validation to restrict the maximum field length in InfoPath, you can use the string-length function in a The expression data validation condition to check whether the amount of characters entered in a field is greater than the maximum characters allowed, and then display an error message.

For example, in Figure 1, I’ve created a data validation condition to check whether the maximum length of a piece of text in a multi-line text box (field1) exceeds 10 characters. This technique also works for rich text boxes in InfoPath.

Caveat: Spaces and line breaks are counted as characters.

Data validation condition to check maximum field length in InfoPath

Figure 1. Data validation condition to check maximum field length in InfoPath.

Now whenever you type more than 10 characters into the field that has the data validation set on it, you’ll see a red border appear. And if you hover over the field, a tooltip containing the error message will appear as shown in Figure 2.

Error message in InfoPath when the maximum field length is exceeded

Figure 2. Error message in InfoPath when the maximum field length is exceeded.

Working with InfoPath