Errors Collection

InfoPath Developer Reference

Contains an Error object for each error within a Microsoft Office InfoPath 2007 form.

Version Information
 Version Added:  InfoPath 2003

Remarks

An Error object contains information about an InfoPath error, including its detailed message, short message, code, type, and the XML node that is associated with it.

The Errors collection is a full-featured collection—it provides properties and methods for adding, deleting, and gaining access to the Error objects that it contains.

In addition to managing the errors generated by InfoPath, the Errors collection can also be used to create custom errors using the Add method.

Bb229714.vs_note(en-us,office.12).gif  Note
Custom errors can also be created using the ReportError method of the DataDOMEvent object.

For more information about using the Errors collection, see Handling errors.

Example

The Errors collection is accessed through the Errors property of the XDocument object. The Errors collection is associated with a form's underlying XML document so that when an error occurs, it occurs within the XML document.

In the following example, the Count property of the Errors collection is used get the count of errors currently contained in the collection:

JScript
  XDocument.UI.Alert("Count of errors: " + XDocument.Errors.Count);

To delete a specific error from the Errors collection, use the Delete method, passing the XML code and condition name as arguments:

JScript
  XDocument.Errors.Delete(myXMLNode, "MyErrorName");

To delete all of the errors in the Errors collection, use the DeleteAll method:

JScript
  XDocument.Errors.DeleteAll();

To set a reference to an error within the Errors collection, use the Item property:

JScript
  var objError;

objError = XDocument.Errors.Item(0); // Or... objError = XDocument.Errors(0);

See Also