Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

TreeView, problems with code

Hi experts!

I have a Table with difrent Categories which I want to present on the Form as a TreeView, but I get Error #438 on form load.

Table:
Category      Level 0      Level 1      Level 2      Level      WBS      Header WBS      Credit      Important
Andet      1      1      3      2      1.1.3      1.1.0      No      No
Udgift      2      0      0      0      2.0.0      0.0.0      No      No
Bank      2      1      0      1      2.1.0      2.0.0      No      No
kassekredit      2      1      1      2      2.1.1      2.1.0      No      No

My code:
Private Sub Form_Load()
On Error GoTo Error_Text
    Dim db As DAO.Database
    Dim rsCategory As DAO.Recordset
    Dim rsTitles As DAO.Recordset
    Dim mNode As Node
   
    Set db = CurrentDb
    Set rsCategory = db.OpenRecordset("Category") ', dbOpenDynaset)
    Dim intIndex
   
    Do Until rsCategory.EOF
        Set mNode = Budget_Type_TreeView.Add(1, tvwChild)
        mNode.Text = rsCategory("Category")
        mNode.Tag = "Categoy List" ' Identifies the table.
        mNode.Key = rsCategory("Header WBS")   'rsCategory!PubID & " ID"
        mNode.Image = "closed"
        intIndex = mNode.Index
       
        Set rsTitles = db.OpenRecordset("select * from [Category] Where [Header WBS]= " & rsCategory("WBS"))
        Do Until rsTitles.EOF
           Set mNode = Budget_Type_TreeView.Nodes.Add(intIndex, tvwChild)
            mNode.Text = rsTitles("Category")  
            mNode.Key = rsTitles("WBS")  
            mNode.Tag = "Category"      
            rsTitles.MoveNext
    Loop
        rsCategory.MoveNext
   Loop

Error_Text_end:
    Exit Sub

Error_Text:
    MsgBox Err.Number
    Resume Error_Text_end
   
End Sub

I appresiate if any can see the bug!

Thanks!
Niels
0
Niels_Starskov
Asked:
Niels_Starskov
  • 7
  • 5
1 Solution
 
Niels_StarskovAuthor Commented:
Sorry, the right layout of the Table "Category":
Category            Level 0      Level 1      Level 2      Level      WBS      Header WBS      Credit      Important
Andet            1      1      3      2      1.1.3      1.1.0            No      No
Udgift            2      0      0      0      2.0.0      0.0.0            No      No
Bank            2      1      0      1      2.1.0      2.0.0            No      No
kassekredit      2      1      1      2      2.1.1      2.1.0            No      No
0
 
Harisha M GCommented:
Hi Niels_Starskov,
    What's the error message? On which line are you getting the error?

Bye
---
Harish
0
 
Niels_StarskovAuthor Commented:
Do Until rsCategory.EOF
        Set mNode = Budget_Type_TreeView.Add(1, tvwChild) <-- ERROR!
        mNode.Text = rsCategory("Category")
        mNode.Tag = "Categoy List" ' Identifies the table.
        mNode.Key = rsCategory("Header WBS")   'rsCategory!PubID & " ID"
        mNode.Image = "closed"
        intIndex = mNode.Index

Niels
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Niels_StarskovAuthor Commented:
sorry, forgot the error mesagge, which is 438 Object doesn't support this propperty or method

BR
Niels
0
 
Harisha M GCommented:
TreeView.Node.Add
0
 
Niels_StarskovAuthor Commented:
Sorry mgh_mgharish, same error
0
 
Harisha M GCommented:
I don't know what you want to do in
Set mNode = Budget_Type_TreeView.Add(1, tvwChild)

It should be
Budget_Type_TreeView.Nodes.Add mNode
0
 
Harisha M GCommented:
Sorry ... my mistake... Try this
   
    Do Until rsCategory.EOF
        mNode = Budget_Type_TreeView.Nodes.Add 1,tvwChild,rsCategory("Header WBS"),rsCategory("Category"), "closed"
        intIndex = mNode.Index
       
0
 
Niels_StarskovAuthor Commented:
Now I get this error:
# Error 35600 Index out of bounds

What I am trying is to get a treeview with

     WBS               Level
-------------------------------------
     1.0.0.0            0
           1.1.0         1
                 1.1.1   2
           1.2.0         1
etc.
0
 
Harisha M GCommented:
Where are you getting that error? What is the error?
0
 
Niels_StarskovAuthor Commented:
Here is the error:
     Set mNode = Budget_Type_TreeView.Nodes.Add(1, tvwChild, rsCategory("Header WBS"), rsCategory("Category"), "closed")
Error:
    # Error 35600 Index out of bounds
0
 
Niels_StarskovAuthor Commented:
I found a way to sole this, this code can handle three levels in the TreeView:

Private Sub Form_Load()
On Error GoTo Error_Text
    Dim db As DAO.Database
    Dim rsCategory As DAO.Recordset 'Level 0
    Dim rsTitles As DAO.Recordset   'Level 1
    Dim rsItem As DAO.Recordset     'Level 2
    Dim mNode As Node

    Set mNode = Budget_Type_TreeView.Nodes.Add()
   
    Set db = CurrentDb
    Set rsCategory = db.OpenRecordset("SELECT * FROM [Category] WHERE [Level]=" & 0 & " ORDER BY [WBS] ASC")
    Dim intIndex
   
    Do Until rsCategory.EOF
        Set mNode = Budget_Type_TreeView.Nodes.Add(1, tvwChild)
        mNode.Text = rsCategory("WBS") & " " & rsCategory("Category")
        mNode.Tag = "Categoy List"
        intIndex = mNode.Index
       
        Set rsTitles = db.OpenRecordset("SELECT * FROM [Category] WHERE [Header WBS]= " & "'" & rsCategory("WBS") & "'" & " And  [Level]=" & 1 & " ORDER BY [WBS] ASC")
        Do Until rsTitles.EOF
           Set mNode = Budget_Type_TreeView.Nodes.Add(intIndex, tvwChild)
            mNode.Text = rsTitles("WBS") & " " & rsTitles("Category")
            mNode.Tag = "Category"
            intIndex = mNode.Index
                Set rsItem = db.OpenRecordset("SELECT * FROM [Category] WHERE [Header WBS]= " & "'" & rsTitles("WBS") & "'" & " And  [Level]=" & 2 & " ORDER BY [WBS] ASC")
                Do Until rsItem.EOF
                   Set mNode = Budget_Type_TreeView.Nodes.Add(intIndex, tvwChild)
                    mNode.Text = rsItem("WBS") & " " & rsItem("Category")
                    mNode.Tag = "Sub Category"
                   
                    rsItem.MoveNext
                Loop
            rsTitles.MoveNext
    Loop
        rsCategory.MoveNext
   Loop
   
Error_Text_end:
    Exit Sub

Error_Text:
    MsgBox Err.Number & " " & Err.Description
    Resume Error_Text_end
   
End Sub

BR
Niels
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now