OnValidate Event
This documentation is archived and is not being maintained.

OnValidate Event

Office 2003

Occurs after changes to a form's underlying XML document have been accepted but before the OnAfterChange event occurs.

Function node::OnValidate(ByRef pDataDOMEvent As DataDOMEvent)

pDataDOMEvent Required DataDOMEvent. A reference to the DataDOMEvent object.

Remarks

This event handler does not allow users to cancel an operation.

During the OnValidate event, the form's underlying XML document is placed in read-only mode.

The OnValidate event is typically used for handling errors and working with the Errors collection—for example, adding new errors or deleting existing ones.

Note  In some cases, events related to changes in a form's underlying XML document may occur more than once. For example, when existing data is changed, an insert and delete operation occurs.

Example

In the following partial example from the Events developer sample form, the OnValidate event handler is used to validate contact information. If the data is invalid, the ReportError method of the DataDOMEVent object is used to create an error.

function msoxd__ContactDates::OnValidate(eventObj)
{
   var iNumberOfDays = 0;
   var objEmailDate = XDocument.DOM.selectSingleNode
      ('/Customers/CustomerInfo/ContactDates/EmailCampaignDt');
   var objPhoneContactDate = XDocument.DOM.selectSingleNode
      ('/Customers/CustomerInfo/ContactDates/PhoneContactDt');
   var objRepVisitDate = XDocument.DOM.selectSingleNode
      ('/Customers/CustomerInfo/ContactDates/RepVisitDt');

   // First validate the email and phone contact dates.
   if (!objEmailDate || !objPhoneContactDate)
      return;

   var emailDate = 
      new Date(objEmailDate.text.replace(/(.*)-(.*)-(.*)/, "$2-$3-$1"));
   var phoneContactDate = 
      new Date(objPhoneContactDate.text.replace(/(.*)-(.*)-(.*)/, "$2-$3-$1"));

   if (isNaN(emailDate) || isNaN(phoneContactDate))
      return;

   // Get the number of days between the two dates.
   iNumberOfDays = GetElapsedDays(emailDate, phoneContactDate);

   if (iNumberOfDays < REQUIRED_PHONE_EMAIL_INTERVAL)
      eventObj.ReportError(objPhoneContactDate, 
         "The Phone Contact Start date must occur after " + 
         REQUIRED_PHONE_EMAIL_INTERVAL + 
         " days from the start of the Email Campaign.", false);
   ...
}


Applies to | DataDOM Object


Show:
© 2016 Microsoft