Treeview problem

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
 
G

Graham Mandeno

Hi Sandy

I can't see why your code is not working, but you might like to try using
the Link Master/Child Fields properties of the subform control instead of
changing the recordsource of the subform. This should certainly be more
efficient.

Add an unbound textbox "txtItemKey" to your main form. For the subform
control (Child33), set LinkMasterFields to txtItemKey and LinkChildFields to
id. (Also, I suggest you rename Child33 to sbfItem or some such!)

Now, change your code as follows:

If Me.TreeViewQs.SelectedItem.Text <> "Items" Then
txtItemKey = Nz(CLng(Mid(TreeViewQs.SelectedItem.Key, 2)))
sbfItem.Visible = True
Else
sbfItem.Visible = False
End If
 

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

Similar Threads


Top