Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185

    Question Unanswered: Tree View in Forms

    Hi folks,
    I would like to know if it is possible in MS-Access forms to show data in tree view like directories in windows? any help would be appreciated.
    Cheers

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you have access to a treeview control then yes. check to see if you have a treeview control Insert | Activex control

    otherwise you need to get hold of one.. there are plenty of tree controls, most of which do something a leetle bit better, or slightly more specialised than the Microsoft control

    Im don't know where my version of the Microsoft tree control came from, but it may not have been part of the Office installation that supplies Access

  3. #3
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    oops I found it, but I am novice with activex controls, I inserted it in my form but it doesnt work? how should I link it to my data? thx.
    Last edited by Aran1; 03-11-08 at 08:25.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I can't rememebr offhand... but it definitely says its a treeview control.. its an activex control NOT a reference BTW

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    It's a stab in the dark but it's right most of the time

    Microsoft Office ##.# Object Library

    EDIT: wrong end of the stick
    George
    Home | Blog

  6. #6
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    oops I found it, but I am novice with activex controls, I inserted it in my form but it doesnt work? how should I link it to my data? thx.

  7. #7
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Smile Write code maby

    Quote Originally Posted by Aran1
    oops I found it, but I am novice with activex controls, I inserted it in my form but it doesnt work? how should I link it to my data? thx.
    For each item that you want to diplay in your treeview
    you should add it in there by looping through your
    recordset("Item")

    Next you should allso add code

    when you click on a item what it should do.

    Allmost even wrote the whole code for you
    if you can read it
    Greetz Marvels -^.^-
    Developments : VB4 Through .Net; Basic; DOS ; CNC ; Sinclair
    Databases : SQL Server Through 2005; Access 3 Through 2003 ; Oracle 8 & 9.i ;
    OS : Win 3.11 Through XP ; NortonComander ; DOS

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    hows your googling?

    I've never used a tree control in Access, so I don't know myself

  9. #9
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    Marvels,
    Your answer is compacted and difficult to manage with that information, can you explain more? I think it will help to realize how to use ActiveX for everbody here

  10. #10
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    hows this for an explanation

    1. Start Microsoft Access and open the sample database Northwind.mdb.
    2. Create a new form in Design view, not based on any table or query.
    3. On the Insert menu, click ActiveX Control.
    4. Select Microsoft TreeView Control, version 6.0 in the Insert ActiveX Control dialog box, and then click OK.
    5. Set the following properties for the TreeView control:
    TreeView control
    Name: xTree
    Width: 4" or 10 cm
    Height: 3" or 7 cm
    6. Double-click the TreeView control to open the TreeCtrl Properties dialog box. On the General tab, select 6 - tvwTreelinesPlusMinusText in the Style box, and then click OK.
    7. On the View menu, click Code, and in the Visual Basic Editor, type the following line if it is not already present:
    Option Explicit
    8. Type or paste the following procedures:'=================Load Event for the Form=======================
    'Initiates the routine to fill the TreeView control
    '================================================= ===========
    Code:
    Private Sub Form_Load()
    Const strTableQueryName = "Employees"
    Dim db As DAO.Database, rst As DAO.Recordset
    Set db = CurrentDb
    Set rst = db.OpenRecordset(strTableQueryName, dbOpenDynaset, dbReadOnly)
    AddBranch rst:=rst, strPointerField:="ReportsTo", strIDField:="EmployeeID", strTextField:="LastName"
    End Sub
    
    '================= AddBranch Sub Procedure ======================
    '      Recursive Procedure to add branches to TreeView Control
    'Requires:
    '   ActiveX Control:  TreeView Control
    '              Name:  xTree
    'Parameters:
    '               rst:  Self-referencing Recordset containing the data
    '   strPointerField:  Name of field pointing to parent's primary key
    '        strIDField:  Name of parent's primary key field
    '      strTextField:  Name of field containing text to be displayed
    '=============================================================
    Sub AddBranch(rst As Recordset, strPointerField As String, _
                  strIDField As String, strTextField As String, _
                  Optional varReportToID As Variant)
       On Error GoTo errAddBranch
       Dim nodCurrent As Node, objTree As TreeView
       Dim strCriteria As String, strText As String, strKey As String
       Dim nodParent As Node, bk As String
       Set objTree = Me!xTree.Object
       If IsMissing(varReportToID) Then  ' Root Branch.
          strCriteria = strPointerField & " Is Null"
       Else  ' Search for records pointing to parent.
          strCriteria = BuildCriteria(strPointerField, _ 
               rst.Fields(strPointerField).Type, "=" & varReportToID)
          Set nodParent = objTree.Nodes("a" & varReportToID)
       End If
    
          ' Find the first emp to report to the boss node.
       rst.FindFirst strCriteria
       Do Until rst.NoMatch
             ' Create a string with LastName.
          strText = rst(strTextField)
          strKey = "a" & rst(strIDField)
          If Not IsMissing(varReportToID) Then  'add new node to the parent
             Set nodCurrent = objTree.Nodes.Add(nodParent, tvwChild, strKey, strText)
          Else    ' Add new node to the root.
             Set nodCurrent = objTree.Nodes.Add(, , strKey, strText)
          End If
             ' Save your place in the recordset so we can pass by ref for speed.
          bk = rst.Bookmark
             ' Add employees who report to this node.
          AddBranch rst, strPointerField, strIDField, strTextField, rst(strIDField)
          rst.Bookmark = bk     ' Return to last place and continue search.
          rst.FindNext strCriteria   ' Find next employee.
       Loop
    
    exitAddBranch:
       Exit Sub
    
          '--------------------------Error Trapping --------------------------
    errAddBranch:
       MsgBox "Can't add child:  " & Err.Description, vbCritical, "AddBranch Error:"
       Resume exitAddBranch
    End Sub
    9. Save the form as frmEmployeeTree.
    10. In the Visual Basic Editor, on the Debug menu, click Compile Northwind.
    11. Open frmEmploeeTree in Form view, and then double-click one or more names in the TreeView control to expand and collapse the branches in the employee hierarchy.
    Greetz Marvels -^.^-
    Developments : VB4 Through .Net; Basic; DOS ; CNC ; Sinclair
    Databases : SQL Server Through 2005; Access 3 Through 2003 ; Oracle 8 & 9.i ;
    OS : Win 3.11 Through XP ; NortonComander ; DOS

  11. #11
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    Marvels,
    I so appreciate for your kind information, i'am sure everybody will use this code.
    in addition i have office 2007 and it doesn't generate the "Employees" query hence I receive error and can not execute the code, can you put the SQL of the query also here?
    thanks a lot and appreciate.
    Cheers

  12. #12
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Aran
    marvels has done most of the work, why don't you at least try to write the query YOU need to access YOUR data

  13. #13
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    Dear All,
    Aran
    marvels has done most of the work, why don't you at least try to write the query YOU need to access YOUR data
    healdem is right and I appreciate so much for your helps, if Marvels agree I will make a small file and put it in Code Bank for future references.
    Cheers

  14. #14
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    It would be nice to have an example of using the TreeView control in the code bank. I've got an example buried somewhere in my archives but I'm not sure how complete it is. I think I got it from the Sybex Access Handbook. I think there's a couple of different TreeView type controls showing information in different ways. Somewhere I've seen one which does the nice + and - to expand the data. I'll see if I can dig through all the hundred mdb's and find it.
    Last edited by pkstormy; 03-12-08 at 02:13.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  15. #15
    Join Date
    Sep 2007
    Location
    Global Village
    Posts
    185
    in fact I still working on marvels code but I found another two codes in the old posts and used one of em and it works, as soon as i complete the marvels code I will put all three examples in the code bank.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •