D
Dale_Fye via AccessMonster.com
I'm trying to remove a node from a treeview, elegantly.
I'm currently deleting the associated record from the underlying table, then
clearing the tree and rebuilding it (not very elegant). I've got the
following code which should allow me to identify the parent node of the
selected node, but it keeps generating a 35602 - Invalid Key error on the
line marked with the <-----
Dim tvw As MSComctlLib.TreeView
Dim nd As MSComctlLib.Node
On Error GoTo DeleteError
If MsgBox("Delete activity", vbCritical + vbYesNo, "") = vbNo Then Exit
Sub
Set tvw = Me.tree_Activities.Object
Set nd = tvw.Nodes(Me.txt_Activity_ID) '<----
When I set a breakpoint on this line, and then go to the Immediate window and
duplicate it, it generates the same error, but when I replace Me.
txt_Activity_ID with the literal "A267" in the immediate window it works
properly, and I can identify the nodes parent, the number of siblings, ...
Anyone have any ideas?
Also, how do I determine the index number of a particular node as it relates
to its parent node. For example, if I have a nodes that look like:
-FY11
|- Item 2
|- Item 1
|- Item 3
What is the best way to determine that Item 1 is the second node belonging to
FY11? I know I could use nd.Next.key and if that generates an error, try nd.
Previous.key, but I was hoping there was a more elegant way.
I'm currently deleting the associated record from the underlying table, then
clearing the tree and rebuilding it (not very elegant). I've got the
following code which should allow me to identify the parent node of the
selected node, but it keeps generating a 35602 - Invalid Key error on the
line marked with the <-----
Dim tvw As MSComctlLib.TreeView
Dim nd As MSComctlLib.Node
On Error GoTo DeleteError
If MsgBox("Delete activity", vbCritical + vbYesNo, "") = vbNo Then Exit
Sub
Set tvw = Me.tree_Activities.Object
Set nd = tvw.Nodes(Me.txt_Activity_ID) '<----
When I set a breakpoint on this line, and then go to the Immediate window and
duplicate it, it generates the same error, but when I replace Me.
txt_Activity_ID with the literal "A267" in the immediate window it works
properly, and I can identify the nodes parent, the number of siblings, ...
Anyone have any ideas?
Also, how do I determine the index number of a particular node as it relates
to its parent node. For example, if I have a nodes that look like:
-FY11
|- Item 2
|- Item 1
|- Item 3
What is the best way to determine that Item 1 is the second node belonging to
FY11? I know I could use nd.Next.key and if that generates an error, try nd.
Previous.key, but I was hoping there was a more elegant way.