[AccessD] Treeview control

Roz Clarke roz.clarke at donnslaw.co.uk
Tue Apr 29 09:46:54 CDT 2003


Hi all

I've been playing with the treeview control (v6) for the first time today.
I've worked my way through an MS tutorial, adapting it to suit my purposes.

Can anyone help explain why the following code, which should give me 2
levels on the tree, only gives me the 1st level? None of the child nodes
appear.

Private Sub Form_Open(Cancel As Integer)
Dim db As Database
Set db = CurrentDb

Dim nd As Node

Dim cnn As New ADODB.Connection
Set cnn = CurrentProject.Connection

Dim rsLevel1 As New ADODB.Recordset
rsLevel1.Open "qryTopLevelTasks", cnn, adOpenKeyset, adLockOptimistic

Dim rsLevel2 As New ADODB.Recordset
rsLevel2.Open "qry2ndLevelTasks", cnn, adOpenKeyset, adLockOptimistic

Dim intIndex As Integer

rsLevel1.MoveFirst

'add all the top level nodes (tasks with no child records)
Do Until rsLevel1.EOF = True
        Set nd = Treeview.Nodes.Add()
        nd.Text = rsLevel1!tsk_Description
        intIndex = nd.Index
        'add all the 2nd level nodes matching this as parent task
        Do Until rsLevel2.EOF = True
            If rsLevel2!tsk_ParentTaskID = rsLevel1!tsk_TaskID Then
                Set nd = Treeview.Nodes.Add(intIndex, tvwChild)
                nd.Text = rsLevel2!tsk_Description
            End If
            rsLevel2.MoveNext
        Loop      
        rsLevel1.MoveNext
Loop

End Sub

Stepping through the code, the indices match between the parent and child
records and no error comes up.

TIA

Roz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030429/49b7f7ca/attachment.html>


More information about the AccessD mailing list