How to create a navigation tree

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have access 2003, is it possible to create a navigation tree in an access
form, like you see when you open windows explorer and navigate the tree in
the left hand window?
 
If you add a TreeView control in your Form you can create a Navigation Tree.
You'd have to create the Nodes in code and launch this using the Form's
OnOpen or OnLoad events.

If you add a Value to the Nodes Tag Property, the Node_Click event could be
used to say go to a record on a subform or move to a row in ListView control.

What do you want to Navigate exactly?
 
OK. Creating nodes in a TreeView is relatively simple. The bit that'll
require a little thought is producing a table that lists the forms to be
included on your Switchboard, frmSwitchboard. For example frmParent might
lead to frmChild. You might have a table, tblNavigation, with two fields
[strForm], [strDescription], & [strParent] where [strFormName] should be the
table's PrimaryKey.

They will be no entry for frmParent if it represents the Root Node (first
node) of a TreeView but for the frmChild record:
[strForm] = "frmChild"
[strDescription] = "Child Form"
[strParent] = "frmParent"

You'll need to add more records describing the relationships between all the
forms you want to see on frmSwitchboard but the next step is to create
frmSwitchboard:

1 In the database window click on New Form and save this as frmSwitchboard or
similar.
2 In Design View go to Insert, ActiveX controls, & add a TreeView control,
tvwNavigation.
3 In frmSwitchboard add the following code to the OnOpen Property:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
Dim nodRoot As Node
'Create Root Node of TreeView Control.
Set nodRoot = tvwNavigation.Nodes.Add(, , "frmParent","frmParent","Root
Node")
Call CreateNode(nodRoot)

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Name & "_Open Error: " & Err.Number & ": " & Err.Description
Resume Exit_Form_Open
End Sub

4 Add the following function to the Form Module:

Private Sub CreateNode(ByVal nodParent As Node)
On Error GoTo Err_CreateNode
Dim nodChild As Node

'Loops through records creating specified nodes.
With CurrentDb.OpenRecordset("SELECT tblNavigation.* FROM tblNavigation
WHERE (((tblNavigation.strParent)=""" & nodParent.Key & """));",
dbOpenSnapshot)
Do
If .EOF Then
Exit Do
Else
Set nodChild = tvwNavigation.Nodes.Add(nodParent.Key,
tvwChild, ![strForm], ![strDescription])
Call CreateNode(nodChild)
.MoveNext
End If
Loop
.Close
End With

Exit_CreateNode:
Exit Sub

Err_CreateNode:
MsgBox "CreateNode Error: " & Err.Number & ": " & Err.Description
Resume Exit_CreateNode
End Sub

When you open frmSwitchboard the coding will create the TreeView Control Root
Node and add all the other Nodes recursively

That's covered the first step, but doesn't include any images. Also, in the
Explorer window the right hand pane is a ListView control. Do you want to
include a ListView control and what would you want to see in it?

Post again when you've sorted out the basic TreeView layout.
i want to use a navigation tree instead of a switchboard. To navigate to
different forms
If you add a TreeView control in your Form you can create a Navigation Tree.
You'd have to create the Nodes in code and launch this using the Form's
[quoted text clipped - 8 lines]
 
Back
Top