Show All

# ReportError Method

Creates an Error object and adds it to the Errors collection.

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

expression Required. Returns a reference to the DataDOMEvent object.

varNode Required Variant. The XML Document Object Model (DOM) node that the error is associated with.

bstrShortErrorMessage Required String. The text to be used for the short error message.

fSiteIndependent Optional Boolean. Sets the condition for automatic deletion of the Error object. If True, the Error object will be deleted on change for any nodes that matched the XPath expression corresponding to the Error object. If False, the Error object will be deleted when the node returned by the Site property of a given event object has been changed.

bstrDetailedErrorMessage Optional String. The text to be used for the detailed error message.

lErrorCode Optional Long. The number to be used as the error code.

bstrType Optional String. Default value is "modeless". Determines whether the change in value will be automatically rejected or whether the user will be prompted to accept or reject the change. The other value is "modal".

returns A reference to an 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

When the ReportError method of the DataDOMEvent object is called, Microsoft Office InfoPath 2003 creates an Error object and adds it to the Errors collection. Errors are removed from the collection when the validation constraint is no longer invalid, or when they are explicitly removed using the Delete or DeleteAll methods of the Errors collection.

Errors can also be created using the Add method of the Errors collection.

Note Site-independent errors should be used when you want the errors to apply to all XML DOM nodes of the same type. If you want the error to apply to a specific XML DOM node, use site-dependent errors.

## Example

In the following example from the Data Validation developer sample form, the ReportError method of the DataDOMEvent object is used to create a custom error and add it to the errors collection:

    function msoxd__total::OnValidate(eventObj)
    {
       if (parseInt(eventObj.Site.nodeTypedValue, 10) > 75)
          eventObj.ReportError(eventObj.Site, "The total is too high.  " +
             "The total number of blocks cannot be greater than 75.", false);

       if (parseInt(eventObj.Site.nodeTypedValue, 10) < 0)
          eventObj.ReportError(eventObj.Site, "The total is too low.  " +
             The total number of blocks cannot be less than 0.", false);
    }

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp