How to automatically display the first item in a drop-down list box in InfoPath 2003

Article translations Article translations
Article ID: 555838 - View products that this article applies to.
Author: S.Y.M. Wong-A-Ton MVP
Expand all | Collapse all

SUMMARY

This article describes how to automatically display the first item in a drop-down list box that has been populated with values from a data connection to an XML file.

MORE INFORMATION

 
In order to display the first item as the selected item in a drop-down list box, you must set the value of the drop-down list box equal to the value of the first item in the list that populates the drop-down list box. This article uses an XML file to populate a drop-down list box on an InfoPath form and a rule, which uses the position() XPath function, to find the value of the first item in the XML file. This value is then used to set the value of the drop-down list box to display the first item as the selected item.
 
Create an XML file

  1. Open Notepad.
  2. Copy the following XML and paste it into Notepad.
    <?xml version="1.0" encoding="UTF-8"?>
    <items>
      <item>
        <value>MDB</value>
        <displayName>Access</displayName>
      </item>
      <item>
        <value>XLS</value>
        <displayName>Excel</displayName>
      </item>
      <item>
        <value>XSN</value>
        <displayName>InfoPath</displayName>
      </item>
      <item>
        <value>PPT</value>
        <displayName>PowerPoint</displayName>
      </item>
      <item>
        <value>DOC</value>
        <displayName>Word</displayName>
      </item>
    </items>
  3. On the File menu, click Save As.
  4. In the Save As dialog box, click Desktop.
  5. In the Save As dialog box, type items.xml in the File name text box.
  6. In the Save As dialog box, select All Files from the Save as type drop-down list box. 
  7. In the Save As dialog box, click Save.
 
Design an InfoPath form

  1. Start InfoPath. On the File menu, click Design a Form.
  2. In the Design a Form task pane, click New Blank Form.
  3. In the Design Tasks task pane, click Controls.
  4. In the Insert Controls list, click Drop-Down List Box.
    A new drop-down list box that is named field1 is added to the form.
  5. In Microsoft InfoPath Designer, right-click field1, and then select Drop-Down List Box Properties.
  6. In the Drop-Down List Properties dialog box, select Look up values in a data connection to a database, Web service, file, or SharePoint library or list, and then click Add.
  7. In the Data Connection Wizard, leave XML document selected, and click Next.
  8. In the Data Connection Wizard, click Browse.
  9. In the Open dialog box, click Desktop.
  10. In the Open dialog box, click items.xml, and then click Open.
  11. In the Data Connection Wizard, click Next, and then Finish.
  12. Choose Yes when you are prompted to add the XML file to your form so that it will be accessible from other computers.
  13. In the Drop-Down List Box Properties dialog box, click the Select XPath button behind the Entries text box.
  14. In the Select a Field or Group dialog box, click the item node, and then click OK.
  15. In the Drop-Down List Box Properties dialog box, click the Select XPath button behind the Display name text box.
  16. In the Select a Field or Group dialog box, click the displayName node,and then click OK.
  17. In the Drop-Down List Box Properties dialog box, click OK.
 
Create a rule

  1. On the Tools menu, click Form Options.
  2. In the Form Options dialog box, click the Open and Save tab, and then click Rules.
  3. In the Rules for Opening Forms dialog box, click Add.
  4. In the Rule dialog box, click Add Action.
  5. In the Action dialog box, select Set a field's value from the Action drop-down list box.
  6. In the Action dialog box, click the button behind the Field text box.
  7. In the Select a Field or Group dialog box, click field1, and then click OK.
  8. In the Action dialog box, click the button behind the Value text box.
  9. In the Insert Formula dialog box, click Insert Field or Group.
  10. In the Select a Field or Group dialog box, select items (Secondary) from the Data source drop-down list box.
  11. In the Select a Field or Group dialog box, expand the item node, click the value node, and then click Filter Data.
  12. In the Filter Data dialog box, click Add.
  13. In the Specify Filter Conditions dialog box, select The expression from the first drop-down list box.
  14. In the Specify Filter Conditions dialog box, type the following expression in the text box:
    position() = 1
  15. In the Specify Filter Conditions dialog box, click OK.
  16. In the Filter Data dialog box, click OK.
  17. In the Select a Field or Group dialog box, click OK.
  18. In the Insert Formula dialog box, click OK.
  19. In the Action dialog box, click OK.
  20. In the Rule dialog box, click OK.
  21. In the Rules for Opening Forms dialog box, click OK.
  22. In the Form Options dialog box, click OK.
 
Test the InfoPath form

  1. On the toolbar, click Preview Form.
  2. Notice that the drop-down list box automatically displays the first item in the list as soon as the InfoPath form opens.
 
The technique described in this article also works for drop-down list boxes that are populated with values from the form's data source or from a data connection to a database, Web service, or SharePoint library or list.
 

Properties

Article ID: 555838 - Last Review: December 16, 2006 - Revision: 1.0
APPLIES TO
  • Microsoft Office InfoPath 2003
Keywords: 
kbpubmvp kbpubtypecca kbhowto KB555838
COMMUNITY SOLUTIONS CONTENT DISCLAIMER
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com