Add nodes to tree view control

A

accessuser1308

I have built myself a database for tracking my genealogy. I have created a
form containing a treeview control to display my family tree. I have the
following code in my form's on load event to fill the tree....

Dim DB As DAO.Database
Dim rs As DAO.Recordset
Dim strKey As String
Dim strKey2 As String
Dim strKey3 As String
Dim strKey4 As String

Set DB = CurrentDb
Set rs = DB.OpenRecordset( _
"SELECT * " & _
"FROM qrySwitchboard " & _
"ORDER BY qrySwitchboard.BDate, qrySwitchboard.WhoID", dbOpenSnapshot,
dbReadOnly Or dbForwardOnly)

With rs
'Loop through all switchboard-items, adding them to the treeview
While Not .EOF
strKey = !WhoID & ";" & Nz(!MDate) & ";" & Nz(!BDate)
strKey2 = (!Last & !Suff & ", " & !First) & ";" & Nz(!MDate) & ";"
& Nz(!BDate)
strKey3 = (!First & !Middle & !Last & !Suff) & ";" & Nz(!MDate) &
";" & Nz(!BDate)
strKey4 = (!Last & ", " & !First & " " & !Middle) & ";" &
Nz(!MDate) & ";" & Nz(!BDate)

Select Case (!ParentID)
Case 0
TreeView0.Nodes.Add , tvwLast, strKey, !Last & !Suff & ", " &
!First & " m. " & !SpouseName & " " & !MDate ', CStr(!ndImage)
Case 1
TreeView0.Nodes.Add(getNodeIndex(!Mother), tvwChild, strKey,
!Last & !Suff & ", " & !First & " m. " & !SpouseName).ForeColor = 16711680
Case 2
TreeView0.Nodes.Add(getNodeIndex(!Father), tvwChild, strKey,
!Last & !Suff & ", " & !First & " m. " & !SpouseName).ForeColor = 16711680
Case 3
TreeView0.Nodes.Add(getNodeIndex(!Father), tvwChild, strKey,
!Last & !Suff & ", " & !First & " m. " & !SpouseName).ForeColor = 16711680
TreeView0.Nodes.Add(getNodeIndex(!Mother), tvwChild, strKey2,
!Last & !Suff & ", " & !First & " m. " & !SpouseName).ForeColor = 16711680
End Select

.MoveNext
Wend
End With

'Clean up
Set rs = Nothing
Set DB = Nothing
End Sub


This code works rather well for me. I, however, do have one problem. A
'child' will show up under both the 'mother' and the 'father', which is
exactly what I want. The 'mother' and 'father' are both found under their
mothers and fathers. My problem is the new 'child' will only show up under
one instance of the mother or father in the tree. Thus, the child will only
be a subnode under one grandparent (for some reason it is always the
grandfather). Is there a way to make the child appear as a subnode for every
instance where the father is a node, and again for every instance where the
mother is a node? If you need any clarification please let me know.

Thank you in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top