Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

In this article

Overview of data sources

All of the data that appears in a form, whether this is data that a user can select in a list box, drop-down list box, or combo box, or the data that a user adds to a form, is stored in the form's data sources. A data source is made up of fields and groups. In the same way that folders on your hard disk contain and organize your files, fields contain the data that users enter into forms that are based on your form template, and groups contain and organize those fields. The user adds data to controls on a form, and those controls are bound to these fields. For example, imagine that you are designing a form template for an expense report. When users open a form based on your form template, they can put their first, middle, and last names into three text box controls — each text box is bound to a field for the first name, a field for the middle name, and a field for the last name. These name fields are contained in a group called "name."

You can see and work with the fields and groups in your form template's data source in the Data Source task pane.

1. Field

2. Group

Although the structure of the data source does not always match the layout of your form template, similarities are common, particularly for groups and fields that are associated with repeating tables, sections, repeating sections, and optional sections. For example, a table or section is bound to a group in the data source, and all of the controls in the table or section are bound to fields that are part of that group. In the following illustration, the Itemized Expenses repeating table in the expense report form consists of three columns that contain a Date date picker, a Description text box, and a Cost text box. These controls are bound to a date field, a description field, and an amount field, respectively. The table itself is bound to the item group.

A form template can have two types of data sources — a single, main data source, and optionally, one or more secondary data sources.

Top of Page

Main data source

The main data source contains the following:

  • The data that users add when they fill out a form that is based on the form template, such as the data that they enter into a text box. For example, the user types their first, middle, and last names in text boxes that are bound to fields in the main data source.

  • The data from a data connection to a database or Web service, which is used to define the data source of the form template.

The data in the main data source is what users save or submit when they fill out the form. When users save the form so that they can submit it later, users are saving the data in the main data source.

Creating the main data source

When you create a form template, Microsoft Office InfoPath automatically creates the main data source for you. All InfoPath form templates contain a single, main data source. Fields and groups can be added to the main data source, depending on the type of form template you create:

Blank form template    You add fields and groups to the main data source by using the Data Source task pane or by dragging a control from the Controls task pane onto a view in the form template. When you drag a control onto a view, InfoPath adds fields and groups to the main data source according to the type of control you are adding. For example, if you drag a text box control onto your form template, InfoPath adds a field to the main data source. If you drag a repeating section control onto your form template, InfoPath adds a group to the main data source. If you drag a repeating table control onto your form template, InfoPath adds two groups to the main data source for the repeating table and adds a field to the main data source for each column in the table.

Form template based on an XML document    InfoPath adds fields and groups that map to the elements that are defined in the schema or to the elements in the document.

Form template based on a Microsoft Office Access database or Microsoft SQL Server database     InfoPath adds fields and groups to the main data source, based on the way that the database stores data.

Form template based on a Web Service    InfoPath adds fields and groups that map to the schema that is supplied by the Web service.

If the data source — for example, a Web service or database — is not contained in the form template, it is referred to as an external data source. InfoPath forms connect to these external data sources through a data connection.

Modifying the main data source

You can add additional fields and groups to the main data source, depending on the existing fields or groups in the main data source. The following table outlines what you can add to existing fields or groups, based on the icons that appear in the Data Source task pane.

Icon

What you can add

Group icon    You can add groups or fields to this group. This icon represents either a group that was added to the main data source by using the Data Source task pane, or a control associated with this group that was dragged from the Controls task pane onto a view in a blank form template.

Field icon    You can add only fields to this field. This icon represents either a field that was added to the main data source by using the Data Source task pane, or a control associated with this field that was dragged from the Controls task pane onto a view in a blank form template.

Locked group icon    You cannot add fields or groups to this group. This group is based on a data connection to an external data source.

Locked field icon    You cannot add fields to this field. This field is based on a data connection to an external data source.

If you drag a control onto a view in a form template, and that form template contains fields and groups that are based on a data connection, you must bind that control to the existing fields and groups in the main data source. InfoPath does not automatically add fields and groups to a form template that contains fields and groups that are based on external data sources. Find links to more information about adding fields and groups in the See Also section.

Note: If your users already filled out forms that are based on your form template, the following changes to the form template's main data source can cause data loss in those forms:

  • Moving, deleting, or renaming a field or group

  • Changing a repeating field or group to a nonrepeating field or group

  • Changing a Rich Text data type to a different data type

For fields and groups that you can modify, you can change the following properties:

Name    The name of the field or group.

Name requirements

  • Each name in the main data source must be unique. If you must use the same name for more than one field or group, create a reference to that field or group instead. When you create a reference to a field or group, InfoPath creates a new, identical field or group whose properties are linked to the properties of the first field or group. Any changes to one field or group automatically update the other, referenced field or group. Reference groups, like reference fields, contain the same fields and groups and share the same properties.

  • Names cannot contain spaces.

  • Names must begin with an alphabetic character or underscore (_), and they can contain only alphanumeric characters, underscores, hyphens (-), and periods (.).

In addition to these requirements, it is a good idea to use a name that describes the contents of the field or group. For example, if you have a group that contains the itemized details of expenses, name the group ItemizedExpense. For a field in a group that contains the amount of the expense, name the field expense.

Type    Defines whether an item in the main data source is a field or a group. A field has a unique value, and a group contains other fields.

Types of fields and groups

Type

When to use

Field (attribute)

Use this type for a field if one or more of the following apply:

  • The field cannot contain other groups or fields.

  • The field must be in an element field.

  • The field is not repeated.

  • The field must always contain a value.

  • The field is any data type other than Rich Text (XHTML).

  • The database or Web service requires an attribute field.

Field (element)

Use this type for a field if one or more of the following apply:

  • The field can contain other attribute fields.

  • The field is part of a group.

  • The field is repeated in a group.

  • The database or Web service requires an element field.

Element fields can be any data type and may or may not have a default value.

Group

Use this type for a group that can contain other fields or groups.

Group (choice)

Use this type if the group can contain only one of several different types of fields or groups of fields.

For example, imagine that you are designing a form template that suppliers in the United States and in countries and regions in the European Union will use, and your form template contains an address choice group. The address choice group contains a group with fields for an address in the United States or a group with fields for an address in a country or region in the European Union. When the user opens the form that is based on this form template, the user can choose to enter an address in the United States or an address in another country or region. The controls that are bound to the fields in the appropriate group appear on the form.

Complete XML Schema or XML document

Use this element type if you want to add an additional XML Schema or XML document to a specified location in the data source.

Data type    Defines the kind of data that a field can store.

List of available data types

Data type

When to use

Text

Use this data type for an element or attribute field that contains unformatted text.

Rich Text

Use this data type for an element field that contains formatted text. You cannot use this data type for attribute fields.

Whole Number

Use this data type for an element or attribute field that contains numbers without decimal values.

Decimal

Use this data type for an element or attribute field that contains currency values or numbers with decimal values.

True/False

Use this data type for an element or attribute field that contains data that can be only one of two values.

Hyperlink

Use this data type for an element or attribute field that contains a Uniform Resource Identifier (URI), such as a hyperlink or a namespace.

Date

Use this data type for an element or attribute field that contains a calendar date.

Time

Use this data type for an element or attribute field that contains a 24-hour time.

Date and Time

Use this data type for an element or attribute field that contains both a calendar date and a 24-hour time.

Picture or File Attachment

Use this data type for an element or attribute field that contains binary data, such as an image or a picture.

Custom

Use this data type for an element or attribute field with custom data types that are defined by a namespace. This data type is typically used for a field or group that is bound to a custom control. The Data namespace box is enabled when you choose this data type.

Note: This table shows only the most common XML data types used in a form template. In InfoPath, you can use any XML 1.0 data type in the World Wide Web Consortium (W3C) recommendations. To use a data type that is not listed in the table, you must extract the form files for a form template and edit the schema (.xsd) file. Find links to more information about extracting the form files for a form template in the See Also section.

Data Namespace    Defines the Uniform Resource Identifier (URI) to add a namespace for a custom data type. This property is available for element or attribute fields with a Custom data type property. When you add a custom control to a form template, this property usually contains a value that is defined by the author of the custom control that is bound to the field.

Default value    Defines the initial value of an element or attribute field when the form is first opened by a user. You can also add formulas to default values, such as the current date, a mathematical calculation, or a reference to another field.

Repeating    Defines whether the element field, attribute field, or group can occur more than once in a form. List controls, repeating sections, repeating tables, and controls that are part of a repeating section or repeating table are bound to repeating fields and repeating groups.

Cannot be blank    Defines whether the element or attribute field must contain a value. If the field does not have a value, the control that is bound to this field is marked with a red asterisk or, for some types of controls, a dashed red border. This property is available only for fields. It is not available for groups.

Top of Page

Secondary data sources

Secondary data sources are data sources in the form that contain data supplied through other data connections to external data sources. For example, imagine that you are creating a form template for an expense report and that you want forms based on the form template to accept expenses in other currencies. However, the currency data is stored in a database. To display the currency data, you add a data connection to that database. The currency data is then stored in a secondary data source and displayed in a list box control on your form template.

The data from additional data connections is stored in secondary data sources and then displayed as choices in controls, such as a list box, combo box, or drop-down list box control, for the user to select when filling out a form. When the user selects an item in a secondary data source, the selection is copied to a field in the main data source.

Secondary data sources differ from the main data source in the following ways:

  • Secondary data sources are optional in a form template. All form templates must have a main data source.

  • A form template can have one or more secondary data sources but only a single, main data source.

  • Fields and groups in a secondary data source are based on the way that data is stored in the external data source, which is connected to the form by using a data connection. These fields and groups cannot be modified by using InfoPath.

  • Unlike the main data source, secondary data sources are not saved with the form.

  • Data in secondary data sources is not typically submitted when the user submits a completed form. However, you can configure your form template to submit the data in the secondary data source to a Web service by using rules or to an e-mail recipient by using custom code.

Creating secondary data sources

When you add a data connection to an external data source that returns data to the form, InfoPath creates a secondary data source automatically. Each data connection that you add to your form template creates a corresponding secondary data source. In the same way that fields and groups are added to the main data source, InfoPath adds fields and groups to the secondary data source. The fields and groups are added to the secondary data source so that they map to the way that the external data source stores the data. You can create a secondary data connection to the following:

  • Web service

  • XML file

  • Microsoft Office Access database or Microsoft SQL Server database

  • List on a site running Microsoft Windows SharePoint Services

When you add a data connection to your form template and create a secondary data source, you can see the fields and groups in the secondary data source in the Data Source task pane. Each secondary data source is shown in this task pane with the name of the data connection followed by Secondary in parentheses.

Modifying secondary data sources

Because the fields and groups in secondary data sources are based on data connections to external data sources, you cannot modify the fields and groups in a secondary data source. When you view a secondary data source in the Data Source task pane, the fields have the locked field icon and the groups have the locked group icon to indicate that you cannot modify them.

Top of Page

Understanding the relationship between a data source and an XML Schema

When a user fills out a form that is based on a form template, the form's main and secondary data sources are stored as XML documents on the user's computer. The structure of the XML document is defined by an XML Schema. An XML Schema is an XML-based file that defines the structure and elements of the XML document, in this case the form, and the data that the elements can contain.

When you create a form template, InfoPath automatically creates the XML Schema that is used to define the structure of the forms that your users will fill out. Each field or group in the data source corresponds to an element in the XML Schema. The properties of each field and group in the data source define the structure of the corresponding elements and the data that each element can contain in the resulting XML document. You can view additional schema details on the Details tab in the Field or Group Properties dialog box, which you can open by double-clicking a field or group in the Data Source task pane.

Top of Page

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×