Undocumented Double Click event of TreeView OCX not working in Access 2010 (1 Viewer)

mdlueck

Sr. Application Developer
Local time
Today, 15:24
Joined
Jun 23, 2011
Messages
2,631
Greetings,

Some time ago, I discovered that the TreeView OCX control supports an undocumented Double Click event in Access 2007. I wrote up a tip about the undocumented feature and published it here:

"Using Double Click event of TreeView from Microsoft Windows Common Controls 6.0 (SP6)"
http://www.access-programmers.co.uk/forums/showthread.php?t=238885

Forms that properly support the undocumented Double Click event on Access 2007 do not support the Double Click event when run with Access 2010. Does anyone have suggestions why Access 2010 would not support as many events as Access 2007 did?
 

MarkK

bit cruncher
Local time
Today, 12:24
Joined
Mar 17, 2004
Messages
8,186
I see this event in the object browser in Access 2007. How is the event undocumented?

Does it make a difference to declare a WithEvents variable?

Code:
private withevents m_tree as mscomctllib.treeview

private sub form_open(cancel as integer)
    set m_tree = me.tree0.object  [COLOR="Green"]'set reference to the object in the control[/COLOR]
end sub

private m_tree_DblClick()
   if not m_tree.selecteditem is nothing then
      msgbox m_tree.selecteditem.text
   end if
end sub
 

mdlueck

Sr. Application Developer
Local time
Today, 15:24
Joined
Jun 23, 2011
Messages
2,631
Thank you, Mark. Indeed that is the work-around to get A2010 supported.

Code:
Option Compare Database
Option Explicit

Private WithEvents ObjM_TreeView As mscomctllib.TreeView

Private Sub Form_Open(Cancel As Integer)

  'Set reference to the control object on the Form
  Set ObjM_TreeView = Me.tvProductReports.Object

End Sub

Private Sub ObjM_TreeView_DblClick()

  Call Me.Select_Click

End Sub
I have a Public Event Select_Click which is the catch-all event for all ways to execute the desired default behavior... pushing the button, double clicking the tree view, etc...

Should I in the Form Close event dereference the WithEvents object to Nothing?

I see this event in the object browser in Access 2007. How is the event undocumented?

I illustrated what I meant by undocumented in the post I referenced / linked to in my original question above.
 
Last edited:

mdlueck

Sr. Application Developer
Local time
Today, 15:24
Joined
Jun 23, 2011
Messages
2,631
hhhmmm... I started receiving the following error when attempting to open the Form with the TreeView control. I had to comment out the WithEvents added code to correct the problem.

Code:
AppErrorMsg: Form: Form_products, Subroutine: btnReports_Click()
Error Source: Fandango_FE
Error Description: The OpenForm action was canceled.
Error Number: 2501
MessageText: The program below needs more memory:
Very odd that it was working, then suddenly started raising the above error. I do not recall further code changes to what I posted above.

The error is "bad enough" that break points on all events that touch the WithEvents object on said Form do not trigger.

P.S. Now after posting, I removed the comments preventing the WithEvents LOCs from executing, restarted Access, and the Form opens properly, the TreeView control responds to Double Click. hhhhmmmm....... :banghead:
 
Last edited:

MarkK

bit cruncher
Local time
Today, 12:24
Joined
Mar 17, 2004
Messages
8,186
I never set objects to nothing on form close. I just let them go out of scope and assume they'll be disposed of. I haven't seen any evidence that this causes a problem, and I don't think WithEvents variables are different in that respect.

And I have, from time to time, had the MSComCtlLib controls get broken in forms and need to be replaced. The symptom of that is when I open the form, Access crashes immediately. The solution is to open the form in design view, delete the control, replace it, rename it, and so on.
 

mdlueck

Sr. Application Developer
Local time
Today, 15:24
Joined
Jun 23, 2011
Messages
2,631
This morning I started with a fresh / compacted-cleaned copy of the A2007 database file. Using A2007 / WinXP I implemented the WithEvents version and commented out the non WithEvents event method I had discovered worked on A2007.

Then I ran through my DB cleanup process:

NT Command Script and Documented Steps to Decompile / Compact / Compile an Access DB
http://www.access-programmers.co.uk/forums/showthread.php?t=219948

I have successfully tested running the DB and verified that the Double Click of the TreeView control works on both A2007 on WinXP and A2010 on Win7.
 

Users who are viewing this thread

Top Bottom