Solved

Allow users to create a dynamic organisational tree diagrammatically

Posted on 2008-10-02
3
434 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
[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
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

752 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