?
Solved

TreeView, problems with code

Posted on 2005-02-27
12
Medium Priority
?
308 Views
Last Modified: 2008-02-01
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
Comment
Question by:Niels_Starskov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 

Author Comment

by:Niels_Starskov
ID: 13414994
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
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13415064
Hi Niels_Starskov,
    What's the error message? On which line are you getting the error?

Bye
---
Harish
0
 

Author Comment

by:Niels_Starskov
ID: 13415150
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Niels_Starskov
ID: 13415165
sorry, forgot the error mesagge, which is 438 Object doesn't support this propperty or method

BR
Niels
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13415213
TreeView.Node.Add
0
 

Author Comment

by:Niels_Starskov
ID: 13415426
Sorry mgh_mgharish, same error
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 1000 total points
ID: 13415463
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
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13415500
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
 

Author Comment

by:Niels_Starskov
ID: 13415556
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
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13415618
Where are you getting that error? What is the error?
0
 

Author Comment

by:Niels_Starskov
ID: 13417857
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
 

Author Comment

by:Niels_Starskov
ID: 13418286
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question