Majp Treeview Error

ClaraBarton

Registered User.
Local time
Today, 13:13
Joined
Oct 14, 2019
Messages
524
Before my form loads I get Error 91 object variable load here:
Code:
Set TVW = New TreeviewForm
Pressing enter moves on and everything seems to work but I can't trace it because it's immediate and doesn't move.
I'm using Version 19
 
Do you have option explicit in the module?
How have you declared TVW?
 
Can you show all the code on the form or at least where you declare and instantiate the TVW?
If you look at the examples at the top of the module TVW is declared.
Public TVW as TreeViewForm

Then it is instantiated in the load event
Set TVW as New TreeViewForm

You can Declare and Instantiate at the same time by replacing both lines with just
Public TVW as New TreeViewForm

I believe I purposely avoided this, but do not remember why.
 
Last edited:
Is this what you need?
Code:
Option Compare Database
Option Explicit
Public WithEvents TVW As TreeviewForm
Private Sub Form_Load()
  Set TVW = New TreeviewForm
  TVW.Initialize Me.XTree.Object, "qryUnion", "None", False, lt_fullload
    With TVW.TreeView
    .Font.Size = 10
    .Font.Bold = True
    .Font.Name = "Times New Roman"
  End With
  DoEvents
    ShowPaths
'  TVW.ExpandTree
End Sub
 
This is strange because you are getting an Object Not Set error when you are trying to set the object. It is usually when you omit the line that you would get the error.

For example if you omitted Set TVW = ... then you would get this error on the next line where you try to use an object before setting it.

I would do a "Compile" and see if something else is not fixed.
When you say it "seems to work" does that mean the tree actually loads.
 
Yes, the tree loads but putting a stop at the first line sends the error before it gets there. I use this treeview on several programs.... File Location data, Recipes & Cookbooks, Nursery database... It works there.
 
I am not seeing a problem especially where that error is. It may be caused by something else and just manifesting there. The only thing I could think is that it is actually breaking in the class. When this happens the code breaks in the code calling the class and not in the class. In order to see if that is the case you can go to Tools, Options, Break in Class Module instead of break in unhandled errors.
break in class.png
 
What does that "with events" qualifier do?

Is there startup code running when you instantiate TVW that could fail without raising an error?

Could you include an onerror trap before the "set NVW" statement?
 
Last edited:
The Class raises custom events. Some of those are simply a wrapper of the treeview events, or a node event. So in your form you can trap all of these events.
Code:
Public Event TreeviewNodeClick(SelectedNode As Node)
Public Event TreeviewNodeCheck(CheckedNode As Node, Checked As Boolean)
Public Event TreeviewNodeDragDrop(DragPK As Variant, DropPK As Variant, DragNode As Node, DropNode As Node)
Public Event TreeviewNodeDblClick(SelectedNode As Node)
Public Event RightClickOnNode(SelectedNode As Node)
Public Event RightClickOffNode()
Public Event NodeIterated(Node As Node)
Public Event ExpandedBranch(ExpandedNode As Node
 
I am so, So, SO, SORRY! I forgot the subform loads first and it's not your error at all. (Not that I ever thought it was!) The subform load event is where the problem is and I am slinking off now...
 

Users who are viewing this thread

Back
Top Bottom