Community articleGetParent function
Added by IBM contributorIBM on May 2, 2012
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.


This function, along with GetChildren, is used to traverse vertically along the form hierarchy. GetParent returns the parent of a node. If the node has no parent, null is returned. A form's structure can be traversed up to the root node using an iterator such as a while loop.


   Function GetParent() As IFormNodeP


There are no parameters for this function.


The IFormNodeP that represents the parent node or null if no such parent exists. If an error occurs, an exception is thrown.


The following sample function receives any form node and returns a reference to the last page of the form. First, the function uses GetNodeType to determine if the supplied node is a the form level. If so, the function uses GetChildren to locate the first page node. If not, the function uses GetParent to locate a page level node. The function then uses GetNext to locate the last page in the form and calls GetReferenceEx to retrieve a reference to that node.
   Function GetLastPage(Node)
      Dim MainNode, TestNode ' objects
      Set MainNode = Node
      ' Locate the page level node that is the nearest ancestor or child of
      ' the current node.  If the node is a form node, get the child.  If the
      ' node is any other type, get the parent until a page node is 
      ' retrieved.
      If MainNode.GetNodeType = UFL_FORM Then 
         Set MainNode = MainNode.GetChildren
         ' Locate the page node of the form by iterating through the parents
         ' of the supplied node.  At the end of this loop, MainNode will be
         ' a page node.
         Do While (Not(MainNode.GetNodeType = UFL_PAGE))
            Set MainNode = MainNode.GetParent
      End If
      ' Set TestNode to be the MainNode (the page node) before beginning the
      ' next loop.
      Set TestNode = MainNode
      ' Locate the last page node by iterating through the siblings of the
      ' global page node.  At the end of this loop, TestNode will be Nothing
      ' and MainNode will be the last page node.
      Do While (Not(TestNode Is Nothing))
         Set MainNode = TestNode
         Set TestNode = TestNode.GetNext
      ' Get a reference to the MainNode and return that reference to the
      ' caller.
      GetLastPage = MainNode.GetReferenceEx(vbNullString, Nothing, Nothing,_
   End Function

Parent topic:
FormNodeP functions