Access 2007 Treeview Sub..with code (1 Viewer)

Toadums

Registered User.
Local time
Yesterday, 17:29
Joined
Feb 22, 2009
Messages
53
Hey!

So i have made a treeView in access 2007, and i made it successfully implement the first tier...but when i go to add children is when it gets funny...

So how the data looks, in column (field??) 1, there are part number, and in number 2 there are sub number...

so for example

Part 1 (in column 1)
.01 (in column 2)

and i need it go do its treeview thing where i see all the part numbers, then click the first one and it expands all the sub groups...

here is my code...i am not fluent in VB...but I do have a sturdy programming knowledge...

I cant really explain exactly what I am trying to do...But here is a picture of what the table i am using looks like:

*edit* ok the image didnt work...so i will try to explain it >.<

the first column has part numbers, and then there is a tier column...
Code:
Part 1              Tier 1
1.1
                     .1
                     .2
                     .3
                     .4
                     .5
1.2

so the first 5 items are: 
1.1.1 *info*
1.1.2 *Info*
1.1.3 *info*
1.1.4 *info*
1.1.5 *info*


So in the tree view of course 1.1 and 1.2 would be the first things you see, and then when you expand 1.1 for example, you would see .1, .2, .3..etc

Thats sort of what the layout is...so i am trying to add the second column in...if the first is empty...hope this makes sense >.<

BTW: the first sub is to insert the first nodes (1.1, 1.2) , second is for the next (.1, .2)


Code:
 Private Sub CreatePartNodes()
  Dim rst As DAO.Recordset

  
  Set rst = CurrentDb.TableDefs!sampleSheet.OpenRecordset

  ' loop through the rows in the recordset
  rst.MoveFirst
  Do Until rst.EOF
  
  If (rst!PartNum <> 0) Then
    With Me.TreeView.Nodes.Add(Text:=rst!PartNum, _
        Key:="prt=" & CStr(rst!PartNum))
      .Expanded = True
    
    End With
    End If
    rst.MoveNext
  Loop
End Sub



Private Sub CreateTier1Nodes()

Dim rst As DAO.Recordset
Dim ptNum 'stores the current part number

Set rst = CurrentDb.TableDefs!sampleSheet.OpenRecordset

rst.MoveFirst

Do Until rst.EOF

    If (rst!PartNum.Value = 0) Then
        
        ptNum = rst!PartNum.Records(-1)
        
        While (PartNum.Value = 0)

        Me.TreeView.Nodes.Add Relationship:=tvwChild, _
            Relative:="prt=" & CStr(rst!ptNum), _
            Text:=rst!tier, Key:="t=" & CStr(rst!tier)
            
            rst.MoveNext
            
            Wend
    End If

rst.MoveNext
Loop



End Sub
Thanks!
Paul
 
Last edited:

Thinh

Registered User.
Local time
Yesterday, 17:29
Joined
Dec 20, 2006
Messages
114
I have a sample database that uses a treeview in the sample database section that is waiting for approval. Once it been approved check it out. it will make life much easier as it acts like a switchboard with a table backing it up.
 

Toadums

Registered User.
Local time
Yesterday, 17:29
Joined
Feb 22, 2009
Messages
53
I have a sample database that uses a treeview in the sample database section that is waiting for approval. Once it been approved check it out. it will make life much easier as it acts like a switchboard with a table backing it up.

Cool thanks... ill keep my eyes open...i didnt even know there was a sample section >.<
 
Last edited:

jardiamj

Registered User.
Local time
Yesterday, 17:29
Joined
Apr 15, 2009
Messages
59
I have done a function that walks through a XML File and populates a TreeView recursively, but it's done in Access 97. I will post it here tomorrow, because it's at the office.
Have a nice day. Cheers!
 
Last edited:

Users who are viewing this thread

Top Bottom