S
Sandy H
Hi
I have created a treeview control that is populated from tblItems when my
form is opened. When a list item is clicked, I have a subform that is bound
to tblItems that I want to display the selected record. My first item (below
the root node) displays correctly but the others, don't appear and the
subform (child33) isn't visible. I have stepped through the code and the
code is definately being run but nothing is happening. Any ideas. My code
is below.
Thanks
Private Sub TreeViewQs_NodeClick(ByVal Node As Object)
Dim lngQ As Long
Dim rs As Recordset
If Me.TreeViewQs.SelectedItem.Text <> "Items" Then
lngQ = Nz(CLng(Mid(TreeViewQs.SelectedItem.Key, 2)))
Me.Child33.Visible = True
Me.Child33.Form.RecordSource = "SELECT * from tblItems WHERE id = "
& lngQ
End If
End Sub
Public Sub FillTree()
Dim nodX As Node
Dim strsql As String
Dim rs As Recordset
strsql = "SELECT * FROM tblItems WHERE parent_id = 0"
Set rs = CurrentDb.OpenRecordset(strsql, dbReadOnly)
Me.TreeViewQs.Style = tvwTreelinesPlusMinusPictureText
'Insert the root node
Set nodX = TreeViewQs.Nodes.Add(, , "root", "Items")
nodX.Bold = True
While Not rs.EOF
Set nodX = TreeViewQs.Nodes.Add("root", tvwChild, "a" & rs!id,
rs!item_text)
nodX.Tag = rs!id
getChild (rs!id)
If intLevelCount > 0 Then 'bold questions that have sub questions
nodX.Bold = True
Else
nodX.Bold = False
End If
rs.MoveNext
Wend
nodX.EnsureVisible ' Show all nodes.
End Sub
Private Sub getChild(parentid As Integer)
Dim rsC As Recordset
Dim strsql As String
Dim nodX As Node
intLevelCount = 0
strsql = "SELECT * FROM tblItems WHERE parent_id = " & parentid
Set rsC = CurrentDb.OpenRecordset(strsql, dbReadOnly)
While Not rsC.EOF
Set nodX = TreeViewQs.Nodes.Add("a" & rsC!parent_id, tvwChild, "a" &
rsC!id, rsC!item_text)
nodX.Tag = rsC!id
intLevelCount = intLevelCount + 1
rsC.MoveNext
Wend
rsC.Close
End Sub
I have created a treeview control that is populated from tblItems when my
form is opened. When a list item is clicked, I have a subform that is bound
to tblItems that I want to display the selected record. My first item (below
the root node) displays correctly but the others, don't appear and the
subform (child33) isn't visible. I have stepped through the code and the
code is definately being run but nothing is happening. Any ideas. My code
is below.
Thanks
Private Sub TreeViewQs_NodeClick(ByVal Node As Object)
Dim lngQ As Long
Dim rs As Recordset
If Me.TreeViewQs.SelectedItem.Text <> "Items" Then
lngQ = Nz(CLng(Mid(TreeViewQs.SelectedItem.Key, 2)))
Me.Child33.Visible = True
Me.Child33.Form.RecordSource = "SELECT * from tblItems WHERE id = "
& lngQ
End If
End Sub
Public Sub FillTree()
Dim nodX As Node
Dim strsql As String
Dim rs As Recordset
strsql = "SELECT * FROM tblItems WHERE parent_id = 0"
Set rs = CurrentDb.OpenRecordset(strsql, dbReadOnly)
Me.TreeViewQs.Style = tvwTreelinesPlusMinusPictureText
'Insert the root node
Set nodX = TreeViewQs.Nodes.Add(, , "root", "Items")
nodX.Bold = True
While Not rs.EOF
Set nodX = TreeViewQs.Nodes.Add("root", tvwChild, "a" & rs!id,
rs!item_text)
nodX.Tag = rs!id
getChild (rs!id)
If intLevelCount > 0 Then 'bold questions that have sub questions
nodX.Bold = True
Else
nodX.Bold = False
End If
rs.MoveNext
Wend
nodX.EnsureVisible ' Show all nodes.
End Sub
Private Sub getChild(parentid As Integer)
Dim rsC As Recordset
Dim strsql As String
Dim nodX As Node
intLevelCount = 0
strsql = "SELECT * FROM tblItems WHERE parent_id = " & parentid
Set rsC = CurrentDb.OpenRecordset(strsql, dbReadOnly)
While Not rsC.EOF
Set nodX = TreeViewQs.Nodes.Add("a" & rsC!parent_id, tvwChild, "a" &
rsC!id, rsC!item_text)
nodX.Tag = rsC!id
intLevelCount = intLevelCount + 1
rsC.MoveNext
Wend
rsC.Close
End Sub