HTW Chur

Hochschule für Technik und Wirtschaft

IKT

Institut für Informations- und Kommunikationstechnologie

IKT Home > Team > Dozenten > Martin Studer > Experience Using InfoPath

Introduction

 

For an internal project a survey based on Microsoft Office InfoPath 2007 was built.  The following text shares some knowledge I gathered during building the InfoPath form.

I welcome any feedback. You will find my mail on the right side. I will put your feedback on the page.

 

Nach oben

Clickable Pictures

 

If you want the user to select from a collection of picture you can of course put an option box next to each picture. To select a picture the user clicks the option box. It is more user-friendly if you allow the user to click on the picture itself.

InfoPath does not support that. Writing some JScript code using the OnContextChange event I came up with a solution that works quite well. See picture below.

 

 

The selected pictures get an orange background.  Try the form from the download section below and have a look at the JScript code. The trick is that every picture is embedded in a section with a special name, for example valueGroup.value.2. The first part of the name is used just for grouping  all sections and not evaluated further. The second part names the prefix for the fields that store the clicks. In the example the prefix is value, so the code looks for fields called value1, value2, value3, … and, in the example form, will find fields value1 and value2. The last part of the name, in the example its 2, depicts the value that the code will set in the fields to record the click. Clicking on a picture triggers an OnContextChange event for section surrounding the picture. The JScript code parses the special name of the section and records the click by writing the value part into the next free field. The code is kind of generic: The number of pictures you can select depends on the number of fields present.

 

Download

   

Nach oben

Hiding Menu Bar and Toolbars in Fill Out-Mode

 

When filling out forms InfoPath by default displays the menu bar and different toolbars.

 

 

 

Usually menu bars are not necessary while filling out forms. And you don't want the people who fill out forms playing around with different menu options. So InfoPath allows you to programmatically hide the menu bar and the toolbars. Article Customizing Menus and Toolbars in InfoPath 2003 from Microsoft Developer Network (MSDN) explains how to do it for InfoPath 2003, but the code works for InfoPath 2007 too. Voila, that's how it should look like.

 

 

The article also explains how to re-enable the menu bar and toolbars. As explained menu bar and toolbars can be disabled on an OnLoad event, so the user who fills out a form never sees the menu or toolbars.

The article warns "If you do not re-enable the controls, they will remain disabled in the InfoPath UI, including in design mode", but the article is not so clear about which event to use for re-enabling. The OnSubmitRequest event is certainly triggered when the user submits a form. But what if the user closes a form by clicking  on the window close button in the top right corner of the InfoPath window? And as the article warns the menu bar and toolbars may be hidden in design mode even. So you may end up with an InfoPath user interface with no menu bars and no toolbars; and you cannot use InfoPath anymore.

It happened to me. I tried to fix the problem by repairing InfoPath through the installation routine. It did not help.

 

Solution 1: Dedicated InfoPath Form

 

Finally I designed a simple InfoPath form on another InfoPath installation that contains a simple button whose code re-enables the menu bar and all toolbars. You can download this form below. As the form needs to execute JScript code that does access menu settings, it needs security level 3, so it is signed. You need to accept the certificate when opening the form.

Back on my developer machine I open this form, click on the button and the menus appear again. Then, important step, don't close the form, but select menu entry File > Design a Form…, and create some new form template. That way InfoPath copies the menu bar and toolbars settings from fill out to design mode. Then close the opened form in fill out mode, then the form in design mode.

Solution 2: Delete .tbs File

 

Delete file

C:\Users\<username>\AppData\Roaming\Microsoft\InfoPath\infopath.tbs

or rename it to infopath.tbs.old. InfoPath seems to store the menu configuration.

Links

Nach oben

Surveys with Multiple Pages

 

Usually surveys consist out of several pages. The user fills out the fields on a page and then switches to the next page. InfoPath does not support multiple pages. But InfoPath supports views. For every page of a survey you can create a view. To switch between views, insert buttons called Back/Next to move between pages.

The disadvantage is that you have to write some validation code yourself, for example check that value from a listbox has been chosen. Usually you want a page to be validated before the user is allowed to move to the next page. InfoPath does this kind of validation only when the user sends a form. You have to write validation code that gets executed when the next button is pressed. 

 

The picture below shows the first page of my example two page survey. There are two fields on the page which should satisfy the indicated conditions ("number may not be empty" and "number must be positive"). If these conditions are not satisfied the user should not be allowed to switch to the next page.

 

 

The picture below shows the rules that get evaluated when pressing the next button. For every field a rule has to be written that displays a dialog box in case the validation fails. The last rule Next finally switches to page 2.

 

 

The checkbox Stop processing rules when this rule finishes must be checked for every rule.

 

 

Checkout the example form template in the download section below; press the next button to switch to page 2 to see how it works.

 

Download

 

 

Nach oben

Using Code for Rule Conditions

 

The article Use Code to Determine a Rule Condition by Greg Collins explains how to use code in InfoPath forms for rule conditions. Instead of rewriting a condition again and again you can call a code function. See example in download section.

For me it worked with JScript, but not with C#. Is it because InfoPath calls a global function? JScript has global functions, but C# has not. Maybe that's the reason it does not work.

 

Nach oben

The Survey

 

Finally the survey. I have removed some pages, some code and replaced actual text/pictures with dummy text/pictures, but you get an idea.

 

Download

 

 

Nach oben

Studer Martin Studer Martin, Prof., Dipl. Informatik-Ingenieur ETH
Leiter angewandte Forschung und Entwicklung Institut IKT, Standortleiter MSE, Leiter IKT, Professor
Telefon: +41 (0)81 286 24 43
> E-Mail
> Mehr zur Person