Error Object

Microsoft Office InfoPath

Show All Show All

Error Object

Errors Error

Represents an error in a Microsoft Office InfoPath 2003 form. Each Error object in InfoPath is each associated with an XML Document Object Model (DOM) node from a form's underlying XML document. When data validation fails for a particular XML DOM node, InfoPath creates an Error object and places it in the Errors collection.

Remarks

That are three types of data validation errors that can occur in an InfoPath form:

  • SCHEMA_VALIDATION   Data validation failed as a result of an XML Schema–defined constraint.
  • SYSTEM_GENERATED   Data validation failed as a result of constraints defined in the form definition (.xsf) file or as a result of scripting code calling the ReportError method of the DataDOMEvent object.
  • USER_SPECIFIED   Data validation failed as a result of a custom scripting error using the Add method of the Errors collection.

Note  The Type property of the Error object can be used to determine the type of data validation error that has occurred.

Using the Error Object

The Error object provides a number of properties that can be used to programmatically interact with an InfoPath data validation error. The Error object is accessed through the Errors property of the XDocument object, which returns a reference to the Errors collection.

In the following example, the Item property of the Errors collection is used to set a reference to an Error object; then the ShortErrorMessage property of the Error object is is used to display the error message in a message box:

    var objError;

objError = XDocument.Errors(0);
XDocument.UI.Alert("Error message: " + objError.ShortErrorMessage);
  

For more information about using the Error object, see Handling errors.