Can someone recommend a simple Access DB that uploads manuals, etc. and outputs as a Tree View? (1 Viewer)

pityocamptes

Registered User.
Local time
Today, 00:42
Joined
Dec 8, 2010
Messages
27
Looking at a simple DB that will allow a user to construct a DB like explorer or a shard point, wherein you have a main folder called Forms, and then child files that correspond to that. With the ability to output on the same screen as a tree view, scroll through, maybe change order, upload, download read document, etc. Thanks
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:42
Joined
Feb 19, 2002
Messages
43,275
Looking at a simple DB that will allow a user to construct a DB like explorer or a shard point, wherein you have a main folder called Forms, and then child files that correspond to that. With the ability to output on the same screen as a tree view, scroll through, maybe change order, upload, download read document, etc. Thanks
Seems like File Explorer already does this. I'm not sure what value is being added by recreating this particular wheel in Access.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:42
Joined
May 21, 2018
Messages
8,529
From the other forum
I found a database free online that will work for me to save technical manuals and other documents. What I would like is a front end that shows a tree structure that will allow a user to click on the structure and open up the files and read or download. The back end, which I can do is linking this to the main page that allows someone to create a technical articles or upload one. Anyone help out or know the best way? Thanks.

So the question is where are the documents saved. If they saved in a windows folder then this example does that by spanning the child folders and logging files and folders to a table. Then presents this in a Treeview.

If the Files are in the database then all the same principles apply but would need to add some data for reading and writing from an attachment field.
You will have to explain in detail and describe any value added over what @Pat Hartman points out can be easily accomplished in windows file explorer.
 

pityocamptes

Registered User.
Local time
Today, 00:42
Joined
Dec 8, 2010
Messages
27
Thanks. I found an access database with the tree view that allows the user to move the items in the tree around. The db is going to be a simple document repository. How would I adjust this code so that a person could insert a description for a Parent header but the children will be uploaded documents, such as forms. This code wont allow attachments to be uploaded although I am able to save attachments into the main database, they wont appear in the tree. Any help appreciated. Thanks.


Code:
Sub LoadTreeView()
Dim strKey As String
Dim strPKey As String
Dim strText As String
Dim strsQL As String

strsQL = "SELECT * FROM Sample ORDER BY ID"

Set db = CurrentDb
Set rst = db.OpenRecordset(strsQL, dbOpenDynaset)
    
tv.Nodes.Clear

'Add all Items are added as Root Nodes
Do While Not rst.BOF And Not rst.EOF
    strKey = KeyPrfx & CStr(rst!ID)
    strText = rst!desc
    tv.Nodes.Add , , strKey, strText
    
    With tv.Nodes.Item(strKey)
        .Image = 1
        .SelectedImage = 4
    End With
    rst.MoveNext
Loop

'Prepare to update the Parent-Key of Nodes
'wherever applicable to move and position the Child Nodes
strPKey = ""
rst.MoveLast
Do While Not rst.BOF
    strPKey = Nz(rst!parentid, "")
    
    If Len(strPKey) > 0 Then
        strPKey = KeyPrfx & strPKey
        strKey = KeyPrfx & CStr(rst!ID)
        strText = rst!desc
        
        'Move the Child Node under it's Parent-Node
        Set tv.Nodes.Item(strKey).Parent = tv.Nodes.Item(strPKey)
        
        'Update Image and SelectedImage Properties
        'with ImageList Index numbers
        With tv.Nodes.Item(strKey)
            .Image = 2
            .SelectedImage = 3
        End With
    End If
    rst.MovePrevious
Loop

rst.Close
Set rst = Nothing
Set db = Nothing

End Sub
 

pityocamptes

Registered User.
Local time
Today, 00:42
Joined
Dec 8, 2010
Messages
27
Here is the entire code:

Code:
Option Compare Database
Option Explicit

Dim tv As MSComctlLib.TreeView
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim imgListObj As MSComctlLib.ImageList
Const KeyPrfx As String = "X"

Private Sub Form_Open(Cancel As Integer)

Set tv = Me.TreeView0.Object

Set imgListObj = Me.ImageList1.Object
tv.ImageList = imgListObj

LoadTreeView

End Sub

Sub LoadTreeView()
Dim strKey As String
Dim strPKey As String
Dim strText As String
Dim strsQL As String

strsQL = "SELECT * FROM Sample ORDER BY ID"

Set db = CurrentDb
Set rst = db.OpenRecordset(strsQL, dbOpenDynaset)
    
tv.Nodes.Clear

'Add all Items are added as Root Nodes
Do While Not rst.BOF And Not rst.EOF
    strKey = KeyPrfx & CStr(rst!ID)
    strText = rst!desc
    tv.Nodes.Add , , strKey, strText
    
    With tv.Nodes.Item(strKey)
        .Image = 1
        .SelectedImage = 4
    End With
    rst.MoveNext
Loop

'Prepare to update the Parent-Key of Nodes
'wherever applicable to move and position the Child Nodes
strPKey = ""
rst.MoveLast
Do While Not rst.BOF
    strPKey = Nz(rst!parentid, "")
    
    If Len(strPKey) > 0 Then
        strPKey = KeyPrfx & strPKey
        strKey = KeyPrfx & CStr(rst!ID)
        strText = rst!desc
        
        'Move the Child Node under it's Parent-Node
        Set tv.Nodes.Item(strKey).Parent = tv.Nodes.Item(strPKey)
        
        'Update Image and SelectedImage Properties
        'with ImageList Index numbers
        With tv.Nodes.Item(strKey)
            .Image = 2
            .SelectedImage = 3
        End With
    End If
    rst.MovePrevious
Loop

rst.Close
Set rst = Nothing
Set db = Nothing

End Sub


Private Sub TreeView0_NodeClick(ByVal Node As Object)
Dim SelectionNode As MSComctlLib.Node
    
'Ensure that the clicked node equals the selected node in the tree
If Not Node Is Nothing Then
    Set SelectionNode = Node
       If SelectionNode.Expanded = True Then
            SelectionNode.Expanded = False
        Else
            SelectionNode.Expanded = True
        End If
End If
End Sub

Private Sub cmdCollapse_Click()
Dim tmpnod As MSComctlLib.Node
For Each tmpnod In tv.Nodes
    If tmpnod.Expanded = True Then
        tmpnod.Expanded = False
    End If
Next

End Sub

Private Sub cmdExpand_Click()
Dim tmpnod As MSComctlLib.Node
For Each tmpnod In tv.Nodes
    If tmpnod.Expanded = False Then
        tmpnod.Expanded = True
    End If
Next

End Sub


Private Sub TreeView0_OLEStartDrag(Data As Object, AllowedEffects As Long)
    Set Me.TreeView0.SelectedItem = Nothing
End Sub


Private Sub TreeView0_OLEDragOver(Data As Object, _
                                Effect As Long, _
                                Button As Integer, _
                                Shift As Integer, _
                                x As Single, _
                                y As Single, _
                                State As Integer)
    
    Dim SelectedNode As MSComctlLib.Node
    Dim nodOver As MSComctlLib.Node
    
    If tv.SelectedItem Is Nothing Then
        'Select a node if one is not selected
        Set SelectedNode = tv.HitTest(x, y)
        If Not SelectedNode Is Nothing Then
            SelectedNode.Selected = True
        End If
    Else
        If tv.HitTest(x, y) Is Nothing Then
        'do nothing
        Else
            'Highlight the node the mouse is over
            Set nodOver = tv.HitTest(x, y)
            Set tv.DropHighlight = nodOver
        End If
    End If

End Sub


Private Sub TreeView0_OLEDragDrop(Data As Object, _
                                    Effect As Long, _
                                    Button As Integer, _
                                    Shift As Integer, _
                                    x As Single, _
                                    y As Single)

    Dim sourceNode As MSComctlLib.Node
    Dim SourceParentNode As MSComctlLib.Node
    Dim targetNode As MSComctlLib.Node
    
    Dim tmpRootNode As MSComctlLib.Node
    Dim strtmpNodKey As String
    Dim ChildNode As MSComctlLib.Node
    
    Dim strSPKey As String
    Dim strTargetKey As String
    
    Dim strsQL As String
    Dim intKey As Integer
    Dim intPKey As Integer
    
    On Error Resume Next
    
    Select Case Screen.ActiveControl.Name
            
           Case TreeView0.Name
                Set sourceNode = tv.SelectedItem
            
    End Select
    
    'Get Source Parent Node & Target Node Reference
    Set SourceParentNode = sourceNode.Parent
    Set targetNode = tv.HitTest(x, y)
            
    'If any errors then exit
    If Err <> 0 Then
        MsgBox Err & " : " & Err.Description, vbInformation + vbCritical, "OLEDragDrop()"
        Err.Clear
        Exit Sub
    Else
        On Error GoTo 0
    End If
    

    'Get/define Source parent Node Key to compare it with Target Node Key
    If SourceParentNode Is Nothing Then
        strSPKey = "Empty"
    Else
        strSPKey = SourceParentNode.Key
    End If
    
    'Check the Target Node/Location and define the Key
     Select Case True
        Case targetNode Is Nothing
            strTargetKey = "Empty"
            
        'if targetNode have a zero length String as Key
        Case targetNode.Key = ""
            strTargetKey = "Empty"
            Set targetNode = Nothing
        Case Else
            strTargetKey = targetNode.Key
     End Select
    
    'Make sure the Target Node is not the source Node's own parent
    If strTargetKey = strSPKey Then Exit Sub
    
    'Track User's Node move action, check for error.
    On Error Resume Next
    
    If targetNode Is Nothing Then
        
        'If target Node is Nothing (the Node dropped in the empty area),
        'then the Node must be moved to the Root-level
        'save the original sourceNode.Key
        strtmpNodKey = sourceNode.Key
        
        'Modify the source Node Key, with addition of some text, say 'Empty', like 'X5Empty'
        'So that a temporary Node can be created with the original source Node key.
        'Note: Two Nodes with the same Key cannot remain in memory at the same time.
        'The Source Node with key 'X5Empty' deleted later,
        'temporary Node takes it's droped location.
        sourceNode.Key = sourceNode.Key & strTargetKey

        'Create the temporary Root Node, with original sourceNode Key
        Set tmpRootNode = tv.Nodes.Add(, , strtmpNodKey, sourceNode.Text)
        
        'define the Root Node image indexes
        With tmpRootNode
            .Image = 1
            .SelectedImage = 4
        End With
        
        'Move all child Nodes from SourceNode,if any,
        'as tmpRootNode's Children
        Do Until sourceNode.Children = 0
            Set sourceNode.Child.Parent = tmpRootNode
            
            'modify Node image indexes
            With sourceNode
                .Image = 2
                .SelectedImage = 3
            End With
        Loop

        'Delete the Source Node with modified Key from TreeView
        tv.Nodes.Remove sourceNode.Index
        
        'Move the tmpRootNode with original Key
        'to the dropped location on TreeView
        Set sourceNode = tmpRootNode
    Else
        'Move the sourceNode under targetNode as child
        Set sourceNode.Parent = targetNode
        
        'modify Node image indexes
        With sourceNode
            .Image = 2
            .SelectedImage = 3
        End With
    End If
    
    'Notify, if there was an Error then Exit, else Update PrentID of related Record.
    If Err <> 0 Then
        MsgBox Err & " : " & "Unable to move:" & vbCrLf & Err.Description, vbInformation + vbCritical, "DragDrop2()"
        Exit Sub
    Else
        'Build and execute the SQL statement to update the record
        If targetNode Is Nothing Then
            intKey = Val(Mid(sourceNode.Key, 2))
            strsQL = "UPDATE Sample SET ParentID = Null" & _
                     " WHERE ID = " & intKey
        Else
            intKey = Val(Mid(sourceNode.Key, 2))
            intPKey = Val(Mid(targetNode.Key, 2))
            
            strsQL = "UPDATE sample SET ParentID = " & intPKey & _
                     " WHERE ID = " & intKey
        End If
        
        'Modify the table records
        CurrentDb.Execute strsQL, dbFailOnError
        
        'If an error raised then refresh TreeView and exit
        If Err <> 0 Then
            MsgBox Err & " : " & Err.Description
            LoadTreeView 'Refresh/display TreeView without changes
        Else
            'Sort Nodes
            If sourceNode.Parent Is Nothing Then
                sourceNode.Root.Sorted = True
            Else
                sourceNode.Parent.Sorted = True
            End If
            
            tv.Nodes(sourceNode.Key).Selected = True
        End If
    End If
    cmdExpand_Click
    
    On Error GoTo 0

End Sub

Private Sub TreeView0_OLECompleteDrag(Effect As Long)

    'Turn off the drophighlight
    Set tv.DropHighlight = Nothing

End Sub

Private Sub Form_Close()

Set tv = Nothing
End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:42
Joined
May 21, 2018
Messages
8,529
My code is a little simpler than that.
Code:
Public WithEvents TVW As TreeviewForm
Private Sub Form_Load()
  Set TVW = New TreeviewForm
  TVW.Initialize Me.XTree.Object, "yourQueryName", "ParentIDValue", True, lt_fullload, True
End sub
That loads the tree, enables drag and drop, loads the images, enables double click events and associates keys with the data.
You just need to add the Header descriptions to the query as described in the class.
 

pityocamptes

Registered User.
Local time
Today, 00:42
Joined
Dec 8, 2010
Messages
27
Ok so I tried modifying MajP DB and if possible would like some help. It is a simple Tree view for a technical manuals, where you have a parent header and underneath you have uploaded pdf files. First, the t_E2E table, what are all the field names related to? Do I need all of them? Also, I tried changing the code some and getting some errors that maybe someone can help out with. Thanks.
 

Attachments

  • MajP TreeviewDemo v18_Full.zip
    2 MB · Views: 63

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:42
Joined
May 21, 2018
Messages
8,529
STOP! You completely missed the point. That database was meant to demonstrate multiple different types of data stored in different tables and then presented in Treeviews. Nowhere do I suggest to use one of these tables to try to put your data into it. E2E was a specific example, Employees another, Orders another. That is like taking a Students template database and sticking Machine Parts data into the fields.
If you did any reading of the original thread it explains how you take existing data and make a query that can be used to load a tree view.

Normally a Treeview is used with Self referencing data where the parent record is in the same table as the child record. See examples in thread.
If it is just a group of related parent child tables, it can still be done but this requires creating separate queries in the correct format then union them together. This is shown in the demo too with Order and Order details

You keep saying you
It is a simple Tree view for a technical manuals, where you have a parent header and underneath you have uploaded pdf files.
I am starting to think you believe someone has this exact structure with the exact features that meets your exact needs and you just have to populate the tables with you data. That is not usually how it works. You may find a general template for doing simple activities, but even that needs to be modified to fit your needs. I post reusable code examples that can be easily incorporated into your application, not complete solutions for exact needs.

If you want help you got to put some work into asking for it. More than " I want a simple Tree view for a technical manuals, where you have a parent header and underneath you have uploaded pdf files. " Need to detail what you need, how your tables are structured, what features are desired. I do not go to my mechanic and drop off my car and simply state "I need you to fix the problem."

So take a big step back and provide your database tables with some populated data. If needed draw it out in word of make some dummy forms to show how you want to add/edit/ and delete data. I can put any table/tables of data into a treeview in 10 minutes of time, but I cannot guess at what this looks like. I am more than willing to show you how to get your data into a Treeview, but I am not going to build a complete application from scratch that incorporates all your needed tables and forms.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:42
Joined
Feb 19, 2002
Messages
43,275
@pityocamptes I also don't think you should infer from @MajP 's most recent response that he is volunteering to create an application for you for free no matter how detailed the specs you post are.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:42
Joined
May 21, 2018
Messages
8,529
If you provide your tables, and additional forms for add, edit and delete I can then add in the treeview and synchronize with the forms. This is a iterative approach. If you look at the original link I posted @dgreen and I went back and forth for over 150 posts to add features and capabilities to the E2E example. He provided detailed explanations each time on the capabilities desired. So I am willing to help out, but you have to do that level of effort.
However. as I mentioned in this thread here

Treeviews work when you have "square" data. Several levels deep and no level extremely long. If it is long and shallow then navigating a tree is less easy than navigating a list or combo. You mention only two levels a Header, and Files. That is not much of a tree, more like a Festivus poll. You could navigate faster with cascading combos, or linked subforms/listboxes. In that same thread I posted above see @Pat Hartman example for presenting something more like you are describing.

Not discouraging you from a Treeview, just not always the best solution for different data presentation. In some cases it is the best means to present information. This is when there are many levels and the number of levels is undetermined. Such as system/subsystems.
 

Users who are viewing this thread

Top Bottom