Thank you for your reply. I had actually tried this approach. My problem is
the query will now have multiple copies of WhoID, based on the number of
parents in the associated table. When I base the tree on this query I get an
error that the index is out of range. The code I am using is below:
'Fill Tree
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strKey As String
Set db = CurrentDb
Set rs = db.OpenRecordset( _
"SELECT * " & _
"FROM qryFamTree " & _
"ORDER BY qryFamTree.BDate, qryFamTree.WhoID", dbOpenSnapshot,
dbReadOnly Or dbForwardOnly)
TreeView0.Nodes.Clear
With rs
'Loop through all FamTree-items, adding them to the treeview
While Not .EOF
'Assemble a key for this node, consisting of three arguments
‘ndObjectType and ndObjectName will allow me to open a picture or document
when node is clicked – this works fine
strKey = !WhoID & ";" & Nz(!ndObjectType) & ";" & Nz(!ndObjectName)
If !Parent > 0 Then
'This node is a child-node of some other node;
'Find the parent node and add it below that node's last child
TreeView0.Nodes.Add(getNodeIndex(!Parent), tvwChild, strKey,
!Last & !Suff & ", " & !First & " m. " & !SpouseName).ForeColor = 16711680
', CStr(!ndImage)
Else
'There is no parent - add this node to the treeview's root
TreeView0.Nodes.Add , tvwLast, strKey, !Last & !Suff & ", " &
!First & " m. " & !SpouseName ', CStr(!ndImage)
End If
.MoveNext
Wend
End With
'Clean up
Set rs = Nothing
Set db = Nothing
End Sub
‘*************************************************************
Private Function getNodeIndex(ByVal strKey As String) As Integer
Dim intCounter As Integer
'Assume failure (return root)
getNodeIndex = 0
For intCounter = 1 To TreeView0.Nodes.Count
'The key being looked for is the first argument
If Split(TreeView0.Nodes(intCounter).Key, ";")(0) = strKey Then
'Found the node
getNodeIndex = intCounter
Exit For
End If
Next intCounter
End Function
qryFamTree has my main table joined to a second table by WhoID. The second
table consists of the parent IDs for each parent the person in the main table
may have. In the query (if the individual had 4 parents) there would be 4
entries for the individual, each one with a different parentID. The form
code errors out when it tries to place the child with a second parent in the
tree.
Thank you for any suggestions