Treeview: Resetting node checkbox in VBA code.

G

Guest

Access 2007/VBA/treeview control:
NodeCheck event in VBA won't allow me to reset checkbox, even when code
establishes addressibility on node in treeview control. Any thoughts? The
event procedure is below:

Private Sub MyTree_NodeCheck(ByVal thisNode As Object)
Dim myTreeView As TreeView
Set myTreeView = Me!MyTree.Object
With myTreeView
If thisNode.Bold Then
Else
.Nodes(thisNode.Index).Checked = True
.Refresh
End If
End With
End Sub

Thanks.
 
G

Guest

I appreciate your suggestion, but unfortunately it does not work.

Goal: Don't allow checkbox to be unchecked if node is reserved by another
project (indicated by text not bold). (This reserved/available status is
established when the treeview control is initially loaded for the form.)

Symptom: if node is bold, everything works fine, checkboxes are handled
properly. But if node text is not bold (signalling that this node is
"reserved"), then I can't seem to uncheck the box, thus properly reinstating
its "reserved" status. The treeview control appears to ignore this
programmatic update of the check box when it exits the NodeCheck event
procedure, leaving the box incorrectly unchecked.

(By the way I had originally used the code you suggested, and when it didn't
work, I thought it was duie to the By Val parameter passing mode of the event
procedure, so that the actual node object in the treeview wasn't being
addressed, which may still be an issue. That is why I went to the more direct
addressing of the node to ensure that I was setting the node in the actual
treeview control, not some copied By Val parameter object that was passed to
the procedure.

Thanks for your thought.
 
G

Guest

Hello Wayne,

You seem to be contradicting your self ...

Goal: Don't allow checkbox to be unchecked if node is reserved by another
project (indicated by text not bold).

--- If NOT Bold Then DO NOT Un-Check

Symptom: ... But if node text is not bold (signalling that this node is
"reserved"), then I can't seem to uncheck the box, thus properly reinstating
....

--- If NOT Bold then un check the box .... which is what you are trying to
prevent right? ...


Your "symptom" is the goal? ... Am I missing something? ... I assume that I
am, in the mean time, may you should programatically BOLD your node first,
then Un-Check it.
 
G

Guest

Thanks for your observation. Sorry if you are confused. Let me restate my
problem: Any thoughts on how I can get the treeview control in an access form
to accept an update to a node's Checked property via the NodeCheck event
procedure. Somehow the code sets the property, but then upon exiting the
event procedure, Access (or something) resets it to its value when the event
procedure was entered.

Anyway, any thoughst are always appreciated.

Thanks.
 
G

Guest

I wonder if the application (ACCESS in this case) when it raises the
NodeCheck event procedure and passses the newly-checked node as a By Val
parameter, prevents any changes to the node properties (consistent with the
By Val argument mode), regardless of adddressibility? In other words, it
simply resets the Checked property to its value when the event was raised,
regardless of how you may try to programmatically change that setting inside
the event procedure itself?

If that is the situation, any ideas on how to work around that?
 
A

Alex Dybenko

ok,
here how you can solve this. declare a class level variable:

private cnode as node

in nodecheck event:

if Node.Bold=false then
Set cnode = Node
end if

in mouseup event:

If Not cnode Is Nothing Then
cnode.Checked = true
Set cnode = Nothing
End If

this works at me and hope it will work at you

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
G

Guest

Excellent. Good work.

While I dislike global variables, this looks to be the best answer for my
problem.

I apprercaitre everyone's thoughtful insights.

Thanks again.
 
A

Alex Dybenko

hi,
great that it helped you, but this is not a global variable, this is a class
module level variable. but you can also make it global if you like

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

wayne said:
Excellent. Good work.

While I dislike global variables, this looks to be the best answer for my
problem.

I apprercaitre everyone's thoughtful insights.

Thanks again.
 

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