Treeview Node Uncheck Issue

T

Trepalium

Hey I'm trying to have all node checkboxes in a particular node group
be unchecked if all of the child nodes are unchecked. I'm using the
code below. All variables in the code are declared in the sub prior to
this with code. When I run this and uncheck an item it gives me a run-
time error:


Run-time Error:
---------------------------------------
Run-time error '91':

Object variable or With block variable not set
---------------------------------------

Code:
----------------------------------------------------
With Me.TreeView2
Set nod = .Nodes.Item(Node.Index).Parent
childcount = nod.Children
check = 0

Do Until childcount = 0
If nod.Child.Next.Checked = True Then
check = check + 1
ElseIf nod.Child.Next.Checked = False Then
check = check
End If
childcount = childcount - 1
Loop

If nod.Child.FirstSibling.Checked = True Then
check = check + 1
ElseIf nod.Child.FirstSibling.Checked = False Then
check = check
End If

If nod.Child.LastSibling.Checked = True Then
check = check + 1
ElseIf nod.Child.LastSibling.Checked = False Then
check = check
End If

If check > 0 Then
nod.Checked = True
ElseIf check = 0 Then
nod.Checked = False
End If
End With
-------------------------------------------------------------


This error only occurs when I have subchildren to a child under the
root node. If I'm just checking a child node directly under the root
node, I do not get this error. I am guessing it has to do with
referencing the root node, but I'm not sure.



Any ideas?



Thanks again for your help.
 

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

Top