<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>Treeview control</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2 FACE="Arial">Hi all</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">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.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">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.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">Private Sub Form_Open(Cancel As Integer)</FONT>
<BR><FONT SIZE=2 FACE="Arial">Dim db As Database</FONT>
<BR><FONT SIZE=2 FACE="Arial">Set db = CurrentDb</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Dim nd As Node</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Dim cnn As New ADODB.Connection</FONT>
<BR><FONT SIZE=2 FACE="Arial">Set cnn = CurrentProject.Connection</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Dim rsLevel1 As New ADODB.Recordset</FONT>
<BR><FONT SIZE=2 FACE="Arial">rsLevel1.Open "qryTopLevelTasks", cnn, adOpenKeyset, adLockOptimistic</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Dim rsLevel2 As New ADODB.Recordset</FONT>
<BR><FONT SIZE=2 FACE="Arial">rsLevel2.Open "qry2ndLevelTasks", cnn, adOpenKeyset, adLockOptimistic</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Dim intIndex As Integer</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">rsLevel1.MoveFirst</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">'add all the top level nodes (tasks with no child records)</FONT>
<BR><FONT SIZE=2 FACE="Arial">Do Until rsLevel1.EOF = True</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Set nd = Treeview.Nodes.Add()</FONT>
<BR><FONT SIZE=2 FACE="Arial"> nd.Text = rsLevel1!tsk_Description</FONT>
<BR><FONT SIZE=2 FACE="Arial"> intIndex = nd.Index</FONT>
<BR><FONT SIZE=2 FACE="Arial"> 'add all the 2nd level nodes matching this as parent task</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Do Until rsLevel2.EOF = True</FONT>
<BR><FONT SIZE=2 FACE="Arial"> If rsLevel2!tsk_ParentTaskID = rsLevel1!tsk_TaskID Then</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Set nd = Treeview.Nodes.Add(intIndex, tvwChild)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> nd.Text = rsLevel2!tsk_Description</FONT>
<BR><FONT SIZE=2 FACE="Arial"> End If</FONT>
<BR><FONT SIZE=2 FACE="Arial"> rsLevel2.MoveNext</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Loop </FONT>
<BR><FONT SIZE=2 FACE="Arial"> rsLevel1.MoveNext</FONT>
<BR><FONT SIZE=2 FACE="Arial">Loop</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">End Sub</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Stepping through the code, the indices match between the parent and child records and no error comes up.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">TIA</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Roz</FONT>
</P>
</BODY>
</HTML>