Solved Reload xtree (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 15:21
Joined
Oct 14, 2019
Messages
468
How can I reload xtree on an open from from a different form?
Code:
    Me.Recordset.Requery
    Me.cboSearch.Requery
          If IsObjectOpen("frmRecipeDetail", acForm) Then
            Forms!frmRecipeDetail.Form.Recordset.Requery
            Forms!frmRecipeDetail.reLoadxTree
            Forms!frmRecipeDetail.Fayt
          End If
End Sub
This gives an error 91... object variable not set on the xtree line
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 15:21
Joined
Oct 29, 2018
Messages
21,474
Is reLoadxTree a Public function/sub?
 

ClaraBarton

Registered User.
Local time
Today, 15:21
Joined
Oct 14, 2019
Messages
468
Code:
Public Sub reLoadxTree()
    TVW.ClearTree
    TVW.Initialize Me.xTree.Object, "qryUnion", "None", False, lt_fullload
    DoEvents
End Sub
It's on the open form that doesn't have the focus
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:21
Joined
May 21, 2018
Messages
8,529
Obviously that code is something I wrote. Looks as if TVW is out of scope, but why? So when you try to operate on it you get error 91.

You could try

Code:
Public Sub reLoadxTree()
    if TVW is nothing then
      Msgbox "For debug purposes. It is out of scope."
      set TVW as New TreeViewForm
    end if
     TVW.ClearTree
    TVW.Initialize Me.xTree.Object, "qryUnion", "None", False, lt_fullload
    DoEvents
End Sub

I believe you can call the ClearTree even if it is not initialized. However, the question is why it goes out of scope.
 

ClaraBarton

Registered User.
Local time
Today, 15:21
Joined
Oct 14, 2019
Messages
468
Of course you wrote it! I use all your stuff! :) ok... working on it
 

ClaraBarton

Registered User.
Local time
Today, 15:21
Joined
Oct 14, 2019
Messages
468
Following your instructions,
Code:
Public Sub reLoadxTree()
'    TVW.ClearTree
'    TVW.Initialize Me.xTree.Object, "qryUnion", "None", False, lt_fullload
'    DoEvents
     If TVW Is Nothing Then
      MsgBox "For debug purposes. It is out of scope."
      Set TVW = New TreeviewForm
    End If
     TVW.ClearTree
    TVW.Initialize Me.xTree.Object, "qryUnion", "None", False, lt_fullload
    DoEvents

End Sub
it goes to this point and fails
Code:
Public Property Get TreeView() As TreeView
  Set TreeView = mTVW
End Property
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:21
Joined
May 21, 2018
Messages
8,529
That shows that the class property "treeview" has gone out of scope or never initialized while the Class instance is declared. That property points to the active X treeview control within the "wrapper" TreeviewForm class. Without seeing it, I cannot explain how that is happening. My guess you are reloading prior to initializing. If that is the case the "TreeviewForm" class does not have a pointer to the TreeView control.

You could do this if this.

Code:
Public Sub reLoadxTree()
     If TVW Is Nothing Then
      Set TVW = New TreeviewForm
    End If
    'Clear the nodes from the active x tree instead where Xtree is name of the ActiveX control
    XTree.nodes.clear  'reference the control directly
    TVW.Initialize Me.xTree.Object, "qryUnion", "None", False, lt_fullload
    DoEvents

End Sub

There was a reason to clear the tree before initializing to ensure you were not "adding" nodes on top of existing nodes. However I see that in the initialize event I have a line of code already to do this. Try simply removing that line and report back if that causes an issue.

Code:
Public Sub reLoadxTree()
     If TVW Is Nothing Then
      Set TVW = New TreeviewForm
    End If
    'clearing of old nodes should happen in the class module
    TVW.Initialize Me.xTree.Object, "qryUnion", "None", False, lt_fullload
    DoEvents
End Sub
 
Last edited:

ClaraBarton

Registered User.
Local time
Today, 15:21
Joined
Oct 14, 2019
Messages
468
the form with the tree is the calling form. Has the tree. works great. But it is not editable. it calls a form for adding editing and deleting. The called form needs to update the first form when any changes are made. The tree was initialized before the called form. I will work more with what you've told me... I originally had the refresh tree on the first form and refreshed after the dialog form was closed and that did the same thing. That's why I moved it to the called form.
 

ClaraBarton

Registered User.
Local time
Today, 15:21
Joined
Oct 14, 2019
Messages
468
Hey!!! it worked! Is that the way I should keep it? Thank you so much.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:21
Joined
May 21, 2018
Messages
8,529
I keep it that way unless you find a problem. I think that may have been a work around before I just cleared the nodes in the initialize event.
 

Users who are viewing this thread

Top Bottom