Retrieve Information From A Parent Document In A View, And All Of The Parent's Child And Grandchil

This example demonstrates how to retrieve information from a parent document in
a view, and all of the Parent's child and grandchild documents. Once all the
child and grandchild documents have been accessed for a parent document , the
next parent and it's associated documents are processed.

Notice the NotesView method GetChild is used to set an object to the first
child document of a parent. GetNextSibling is then used to find any other
child documents. If the object is set to "", there are no more children, and
the code retrieves any grandchild documents. To retrieve the first grandchild
document, GetChild is used with child as a parameter. If a grandchild document
is found, GetNextSibling is used with grandchild as a parameter to retrieve all
the grandchild documents. This is done until grandchild is set to "", at which
time GetNextSibling with a parameter of doc is used to find the next parent
document in the view.

Notes that there are three loops in the example:

________________ Main doc
|________________ Child docs
|________________ Grandchild docs
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
'----------- Also called a responce document
Dim child As NotesDocument
'---------- Also called a responce to a responce
Dim grandchild As NotesDocument
Dim ParentText As Variant
Dim ChildText As Variant
Dim GrandChildText As Variant
Set db = session.CurrentDatabase
'-------- Change "Examples" to the name of your view
Set view = db.GetView("Examples")
Set doc = view.GetFirstDocument()
'-------- Set doc to the first document in the view
While Not(doc Is Nothing)
'-------- Loop until every doc in the view has been checked
ParentText = doc.Subject
Messagebox ParentText(0) + " **This comes from a parent document.**"

Set child = view.GetChild(doc)
'--------- Get the first child of the current doc
While Not(Child Is Nothing)
ChildText = child.Subject
Messagebox ChildText(0) + "**This comes from a response

Set grandchild = view.GetChild(child)
'---------- set grandchild to the first grandchild of the current child
While Not(grandchild Is Nothing)
GrandChildText = grandchild.Subject
Messagebox GrandChildText(0) + "**This comes from a
response to response document.**"
Set grandchild = view.GetNextSibling(grandchild)
'------------ Set grandchild to the next grandchild document in the view
'----------- Set child to the next child document in the view
Set child = view.GetNextSibling(child)
'---------- Set doc to the next parent document in the view
Set doc = view.GetNextSibling(doc)

This was first published in November 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.