Add Method

Microsoft Office InfoPath

Adds an Error object to the Errors collection and returns a reference to the new Error object.

expression.Add(ByVal varNode As Variant, ByVal bstrConditionName As String, ByVal bstrShortErrorMessage As String, [ByVal bstrDetailedErrorMessage As String], [ByVal lErrorCode As Long], [ByVal bstrType As String = "modeless"]) As Error

expression    Required. An expression that returns a reference to the Errors collection.

varNode Required Variant. The XML node that the error will be associated with.

bstrConditionName Required String. The name of the error.

bstrShortErrorMessage Required String. The short message for the error.

bstrDetailedErrorMessage Optional String. The detailed message for the error.

lErrorCode Optional Long Integer. Default value is 0. The error code of the error.

bstrType Optional String. Default value is "modeless". The type of error processing. The other supported value is "modal".

returns    A reference to the newly created Error object.

Security Level

2: Can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

Remarks

The Add method is used to create custom error messages in a Microsoft Office InfoPath 2003 form. There are two types of errors that can be created using the Add method:

  • modeless   The user is notified of the error with an inline alert and can choose to return to the previous value with an undo operation.
  • modal   The user is notified of the error with a dialog box alert. After clicking OK in the dialog box alert, the error will appear as an inline alert and the user can choose to return to the previous value with an undo operation.

Note  Custom errors can also be created using the ReportError method of the DataDOMEvent object.

Example

In the following example, the Add method of the Errors collection is used to create a custom error message:

var objErrors;
var objError;

objErrors = XDocument.Errors;
objError = objErrors.Add(MyXMLNode, "ValidationError", "The data is invalid.");