
I URGENTLY require a recursive database search routine
Quote:
>I have a database with parent and name fields, and I want to create a
>hierarchy from these two fields in Treeview. If the parent field is
>null, then that "node" will be the root.
>The best way I can think of doing this is by writing some sort of
>recursive routine to search the database for the parent and name
>fields any "name" can only have one parent and hence is unique, but a
>"parent" can have many children.
>E.g Search database for "name" where "parent" = "" - make this the
>root node called "name".
>Then search database for "name" where "parent" = name of root node -
>make these children of the root node....etc etc
>Any help would be most appreciated. Thanks.
It's OK I have written one....
Sub AddChildren(Name As String)
Dim NewSearch As Recordset
Dim NewNode As Node
Dim SQL As String, ParentOD As String, NewName As String
Dim I As Integer
SQL = "SELECT * FROM OD WHERE Owning_OD = '" & Name & "'"
Set NewSearch = Dbs.OpenRecordset(SQL, dbOpenDynaset)
If NewSearch.RecordCount = 0 Then
'Exit Sub
Else
NewSearch.MoveNext
Do While Not NewSearch.EOF
ParentOD = NewSearch!OWNING_OD
NewName = NewSearch!OD_NAME
Set NewNode = Treeview1.Nodes.Add(ParentOD, tvwChild, NewName,
NewName, "node")
NewNode.ExpandedImage = "open"
AddChildren (NewName)
NewSearch.MoveNext
Loop
End If
End Sub
Thanks if you were working on it.