Solved

Allow users to create a dynamic organisational tree diagrammatically

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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, when working with VBA, learn some techniques for writing readable and easily maintained code.

809 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