Solved

Allow users to create a dynamic organisational tree diagrammatically

Posted on 2008-10-02
3
424 Views
Last Modified: 2009-07-29
Hi,

Is there a UI control I could use in access that would allow users to create organisational members and have them in a column on the left of the screen and drag them into a drawing area on the right of the screen to create parent/child relationships with branches left and right. I don't think the treeview control works in this way but an example of how it could or an alternative method would be very helpful.

Thanks.  
0
Comment
Question by:geraintcollins
3 Comments
 
LVL 75
ID: 22629509
Not natively in Access ...

See this site:

http://www.dbi-tech.com/product_page_Component_Toolbox.asp

Their treeview control is on steroids compared to Access's built in control.

mx
0
 
LVL 84
ID: 22629729
Even then I seriously doubt you'll be able to build an interface like this in Access. You might could do this in VB or .NET, but Access just ain't built this way ....
0
 

Accepted Solution

by:
geraintcollins earned 0 total points
ID: 22684575
Thanks for the responses, .Net is not currently an option but what I have been able to do is take advantage of the drag and drop functionality of the treeview control to create a recursive organisation structure. I've used the following example as a reference http://www.pointltd.com/Downloads/Details.asp?dlID=36
and adapted the employee recursive structure to meet the organisation structure.  Its working pretty well and I'm going to demo the functionality to the client next week using an access back and front end.  The next step will be to link to SQL Server in development.  I've tested this and realise that this may not be as straightforward as I was hoping as the performance is drastically different.  The issue I'm having is that I'm having to use ADO and can't use the rst.findfirst and nomatch functionality and instead I'm using rst.filter and rst.find but having to move to the start of the recordset each time which is killing the performance.  I've attached the DAO and ADO code below and could do with some help identifying where I could make changes to improve the performance when linking to SQL server. The full source code for the access back end is in the link provided above.  
Access Back End VBA Code: 
 

Public Sub FillChildren(twTree As mscomctllib.Treeview, rst As DAO.Recordset, _

            ByVal nChild As mscomctllib.Node, _

            strParentField As String, strIDField As String, _

            strTextField As String, Optional strTextField2 As Variant, Optional strTextField3 As Variant, Optional strTextField4 As Variant, Optional strTextField5 As Variant, _

            Optional strKeyPrefix As String, _

            Optional varImage As Variant, _

            Optional varImageRst As Variant, _

            Optional fBold As Boolean)

On Local Error GoTo FillChildren_Err
 

    Dim strCriteria As String, Image As Variant, strPrefix As String, strText As String, newNode As mscomctllib.Node

    

    If strKeyPrefix = "" Then

        strPrefix = "a"

    Else

        strPrefix = strKeyPrefix

    End If

    

    If Mid(nChild.Key, 2) = "0" Then

        strCriteria = BuildCriteria(strParentField, rst.Fields(strParentField).Type, "=" & Mid(nChild.Key, 2) & " or is null")

    Else

        strCriteria = BuildCriteria(strParentField, rst.Fields(strParentField).Type, "=" & Mid(nChild.Key, 2))

    End If

    rst.FindFirst strCriteria

    Do Until rst.NoMatch

        strText = Nz(rst(strTextField), " ")

        If Not IsMissing(strTextField2) Then strText = strText & (" " + rst(strTextField2))

        If Not IsMissing(strTextField3) Then strText = strText & (" " + rst(strTextField3))

        If Not IsMissing(strTextField4) Then strText = strText & (" " + rst(strTextField4))

        If Not IsMissing(strTextField5) Then strText = strText & (" " + rst(strTextField5))

        If Not IsMissing(varImageRst) Then

            Image = rst(varImageRst)

        End If

        If (Not IsMissing(varImage)) And (Len(Nz(Image)) = 0) Then

            Image = varImage

        End If

        Image = Nz(Image, "Default")

        Set newNode = twTree.Nodes.Add(nChild, tvwChild, strPrefix & rst(strIDField), strText, Image)

        rst.FindNext strCriteria

    Loop
 

FillChildren_End:

On Error Resume Next

    Exit Sub
 

FillChildren_Err:

    Select Case Err.Number

        Case 35601, 35603

            'Image not found!!!

            Image = "FlagDefault"

            

            Resume

        Case 35602

            'key not unique!!!

            Set newNode = twTree.Nodes(strPrefix & rst(strIDField))

            Resume Next

        Case Else

            MsgBox "Error in FillChildren!!! " & Err.Number & Err.Description

            Stop

            Resume

    End Select

End Sub
 
 

SQL Server linked back end Access VBA code:
 

Public Sub FillChildren(twTree As mscomctllib.Treeview, rst As ADODB.Recordset, _

            ByVal nChild As mscomctllib.Node, _

            strParentField As String, strIDField As String, _

            strTextField As String, Optional strTextField2 As Variant, Optional strTextField3 As Variant, Optional strTextField4 As Variant, Optional strTextField5 As Variant, _

            Optional strKeyPrefix As String, _

            Optional varImage As Variant, _

            Optional varImageRst As Variant, _

            Optional fBold As Boolean)

On Local Error GoTo FillChildren_Err
 

    Dim strCriteria As String, Image As Variant, strPrefix As String, strText As String, newNode As mscomctllib.Node

    

    If strKeyPrefix = "" Then

        strPrefix = "a"

    Else

        strPrefix = strKeyPrefix

    End If

    

    If Mid(nChild.Key, 2) = "0" Then

        strCriteria = strParentField & "=" & Mid(nChild.Key, 2) & " or " & strParentField & " = Null"

        rst.Filter = strCriteria

        

        Do Until rst.EOF

            strText = Nz(rst(strTextField), " ")

            If Not IsMissing(strTextField2) Then strText = strText & (" " + rst(strTextField2))

            If Not IsMissing(strTextField3) Then strText = strText & (" " + rst(strTextField3))

            If Not IsMissing(strTextField4) Then strText = strText & (" " + rst(strTextField4))

            If Not IsMissing(strTextField5) Then strText = strText & (" " + rst(strTextField5))

            If Not IsMissing(varImageRst) Then

                Image = rst(varImageRst)

            End If

            If (Not IsMissing(varImage)) And (Len(Nz(Image)) = 0) Then

                Image = varImage

            End If

            Image = Nz(Image, "Default")

            Set newNode = twTree.Nodes.Add(nChild, tvwChild, strPrefix & rst(strIDField), strText, Image)

            rst.MoveNext

         Loop

         rst.Filter = adFilterNone

    Else

             strCriteria = strParentField & "=" & Mid(nChild.Key, 2)

             

             'Debug.Print rst("EntityName")

             rst.Find strCriteria

           '

             Do Until rst.EOF

                

                 strText = Nz(rst(strTextField), " ")

                 If Not IsMissing(strTextField2) Then strText = strText & (" " + rst(strTextField2))

                 If Not IsMissing(strTextField3) Then strText = strText & (" " + rst(strTextField3))

                 If Not IsMissing(strTextField4) Then strText = strText & (" " + rst(strTextField4))

                 If Not IsMissing(strTextField5) Then strText = strText & (" " + rst(strTextField5))

                 If Not IsMissing(varImageRst) Then

                     Image = rst(varImageRst)

                 End If

                 If (Not IsMissing(varImage)) And (Len(Nz(Image)) = 0) Then

                     Image = varImage

                 End If

                 Image = Nz(Image, "Default")

                 Set newNode = twTree.Nodes.Add(nChild, tvwChild, strPrefix & rst(strIDField), strText, Image)

                 rst.Find strCriteria, 1, adSearchForward

                 If rst.EOF Then

                    rst.MoveFirst

                    Exit Do

                 End If

              Loop

             rst.MoveFirst

    End If
 

FillChildren_End:

On Error Resume Next

    Exit Sub
 

FillChildren_Err:

    Select Case Err.Number

        Case 35601, 35603

            'Image not found!!!

            Image = "FlagDefault"

            

            Resume

        Case 35602

            'key not unique!!!

            Set newNode = twTree.Nodes(strPrefix & rst(strIDField))

            Resume Next

        Case Else

            MsgBox "Error in FillChildren!!! " & Err.Number & Err.Description

            Stop

            Resume

    End Select

End Sub

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now