• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

Allow users to create a dynamic organisational tree diagrammatically

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
geraintcollins
Asked:
geraintcollins
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
geraintcollinsAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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