Treeview initialize

ClaraBarton

Registered User.
Local time
Today, 15:02
Joined
Oct 14, 2019
Messages
764
@MajP I need to update the branch after adding an item:
Code:
Public Sub UpdateBranch()
    Dim tvw                 As TreeviewForm
    Dim ParentNode          As Node
    Dim newNode             As Node
    Dim SelectedNode        As Node
    Dim Key                 As String
    
  Set tvw = GetItemTreeView
  If Not tvw.NodeExists("IT" & Me.ItemID) Then
    Key = CStr("IT" & Me.ItemID)
    Set newNode = tvw.Nodes.Add(, , Key)
  Set ParentNode = tvw.Nodes("LO" & Me.Parent.LocDetail.Form.LocID)
    
    newNode.Text = Me.DocNo & " - " & Me.Item
    newNode.Tag = "IT"
    Forms!frmDetail.FormatNode newNode
    tvw.SelectNode (newNode.Key)
    tvw.TreeView.SelectedItem.Selected = True
  Else
    tvw.Nodes("IT" & Me.ItemID).Text = Me.DocNo & " - " & Me.Item
  End If
  RequerySubforms
End Sub
Code:
Public Function GetItemTreeView() As TreeviewForm
  Set GetItemTreeView = Forms("frmDetail").ItemTreeView
End Function
I get an object defined error when trying to Set tvw
This code is being called from a sub form on the main form that has the treeview.
Do I need to re-initialize the Tree? If I do that I might as well skip the update branch and go for the whole tree?
Suggestions?
 
If in your Main Form you dimensioned
Code:
Private ItemTreeView as TreeviewForm
Then this will fail because the ItemTreeView is private and cannot be accessed
Code:
Set GetItemTreeView = Forms("frmDetail").ItemTreeView
You will need to make it public, or you can add a public Get property to the form.
 
Also is the main form with the tree "FrmDetail"? Check the name.
 
yes it's frmDetail. Now I'm not clear on what you're saying... this is the main form code:
Code:
Public Sub InitTree()
    Dim nd              As Node
    Dim strQry          As String
   
    '  Debug.Print NodeQuery
    If Me.TVWSort = 1 Then
        strQry = "qryNumeric"
    Else: strQry = "qryAlpha"
    End If
   
tvw.Initialize Me.XTree.Object, strQry, "LO", True
    If tvw.Nodes.Count > 0 Then
        Set nd = tvw.Nodes(1)
        nd.Selected = True
           Set tvw.TreeView.DropHighlight = nd
        ConfigureSubForms nd
    End If
   
  FormatTree
  FormatNodes
    tvw.expandtree
End Sub
called from Form_Load
 
In your main form Up top my guess is you declare
Code:
Private (or Public) TVW as TreeviewForm
not as ItemTree. Probably leftover from ItemGenie

If it is Public then I can get a reference to an that object (TVW) on the Main form by
Code:
Forms("frmDetail").TVW
If it is declared private then you cannot get it. So either change to public or you will have to make a public method to return the private variable.

I can get objects or methods from another form by first getting a reference to another form
Forms("SomeForm")
Then I can get any public method or variable by
Forms("SomeForm").Method/Variable

My guess the thing you want to return from frmDetail is the variable TVW witch you declared at the top as TreeviewFrom. Unless you used the item genie name which was ItemTree.
 
at the top of frmDetail:
Code:
Public WithEvents tvw As TreeviewForm
'Private WithEvents subFrmItem As Access.Form
'Private WithEvents subFrmLoc As Access.Form
Public FAYTitems As FindAsYouTypeCombo
 
Code:
Public Function GetItemTreeView() As TreeviewForm
  'Set GetItemTreeView = Forms("frmDetail").ItemTreeView (name/object does not exist on form)
   Set GetItemTreeView = Forms("frmDetail").TVW
End Functio
 

Users who are viewing this thread

Back
Top Bottom