Solved

Allow users to create a dynamic organisational tree diagrammatically

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

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 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