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.


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.


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
   var objPhoneContactDate = XDocument.DOM.selectSingleNode
   var objRepVisitDate = XDocument.DOM.selectSingleNode

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

   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))

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

         "The Phone Contact Start date must occur after " + 
         " days from the start of the Email Campaign.", false);

Applies to | DataDOM Object

© 2016 Microsoft