Thank for the links and info Rob,
But having problem getting it to work, maybe someone can offer some
help with the code I am using...
The problem I am having is it will only fill in the Classifications
for location 1, not location 2 or 3
Need it like this...
'Example:
Locations
Location 1 (Long Beach)
Classification 1 (Plant Equipment)
Classification 2 (Production Equipment)
Location 2 (Texas)
Classification 1 (Plant Equipment)
Classification 2 (Production Equipment)
Option Compare Database
Private db As DAO.Database
Private rstEmployees As DAO.Recordset
Private rstAssets As DAO.Recordset
Private rstLocations As DAO.Recordset
Private rstAssetClassification As DAO.Recordset
Private rstAssetCategory As DAO.Recordset
Private rstAssetSubCategory As DAO.Recordset
'NodeIDs in the treeview collection must be alphabetic.
'Nodes-Unique Key Ledger
'MEN = Menu
'ASSETS = Assets
'LOC = Asset Location
'ACL = Asset Classification
'ACA = Assets Category
'ASC = Assets Sub-Category
'==================================================================
'This procedure populates the TreeView control when the form opens.
'==================================================================
Private Sub Form_Load()
On Error GoTo ErrForm_Load
'Add Statusbar Text...
SysCmd acSysCmdSetStatus, "Setting up treeview"
Set db = CurrentDb
'===============================================================
'Start To Set-Up Our Data, we will need the following
information... '=> Assets (tblAssets)
'=> Asset Classification (tblAssetClassification)
'=> Asset Category (tblAssetCategories)
'=> Asset Sub-Category (tblAssetSubCategories)
'===============================================================
'Open the tblAssets table.
Set rstAssets = db.OpenRecordset("Select * From tblAssets",
dbOpenDynaset)
'Open the tblAssets table.
Set rstLocations = db.OpenRecordset("Select * From tblLocations",
dbOpenDynaset)
'Open the tblAssetClassification table.
Set rstAssetClassification =
db.OpenRecordset("tblAssetClassification", dbOpenDynaset, dbReadOnly)
'Open the tblAssetCategories table.
Set rstAssetCategory = db.OpenRecordset("Select * From
tblAssetCategories Order by CategoryName", dbOpenDynaset)
'Open the tblAssetSubCategories table.
Set rstAssetSubCategory = db.OpenRecordset("Select * From
tblAssetSubCategories Order by SubCategoryName", dbOpenDynaset)
'===============================================================
'End - Data Set-Up
'===============================================================
'Create a reference to the TreeView Control.
Set objTree = Me!TreeView1.Object
'Create a reference to the ImageList
Set objImage = Me.ImageList.Object
'link TreeView object to Imagelist object
Set objTree.ImageList = objImage
'===============================================================
'Add(Relative, Relationship, Key, Text, Image, SelectedImage)
Set nNode = objTree.Nodes.Add(, , "MEN", "Company Equipment Menu",
"Home") 'Root/Parent
nNode.Bold = True 'Set the node text to BOLD
nNode.ForeColor = RGB(0, 0, 5) 'Set the node text Color to
BLACK nNode.BackColor = RGB(255, 255, 255) 'Set the node back
Color to
WHITE
objTree.Nodes("MEN").Expanded = True
'=========================================================================
'Add(Relative, Relationship, Key, Text, Image, SelectedImage)
Set nNode = objTree.Nodes.Add("MEN", tvwChild, "ASS", "All Company
Equipment", "Mixer") 'key is Case sensitive
nNode.Bold = True 'Set the node text to BOLD
nNode.ForeColor = RGB(0, 0, 5) 'Set the node text Color to
BLACK nNode.BackColor = RGB(255, 255, 255) 'Set the node back
Color to
WHITE
Set nNode = objTree.Nodes.Add("ASS", tvwChild, "LOC", "Locations",
"Location")
'===============================================================
' Set-Up Locations & Classifications
'Example:
'Locations
' Location 1 (Long Beach)
' Classification 1 (Plant Equipment)
' Classification 2 (Production Equipment)
' Location 2 (Texas)
' Classification 1 (Plant Equipment)
' Classification 2 (Production Equipment)
'===============================================================
Dim intIndex As Integer ' Variable for index.
Dim KeyIndex As String ' Variable for index.
Do Until rstLocations.EOF
'Extract the Classification's name.
strAssetLocationPointer = rstLocations![LocationID]
strAssetLocation = rstLocations![LocationName]
'Add a root level node to the tree for the supervisor.
'Add(Relative, Relationship, Key, Text, Image, SelectedImage)
Set nNode = objTree.Nodes.Add("LOC", tvwChild, "LOC" & CInt
(rstLocations!LocationID), strAssetLocation, "LocationPic")
intIndex = nNode.Index
KeyIndex = nNode.Key
'First, we must move through the Asset Classification table and
create a Node object for each Category in the table.
Do Until rstAssetClassification.EOF
'Extract the Classification's ID.
strAssetClassificationID = rstAssetClassification!
[AssetClassificationID]
'Extract the Classification's name.
strAssetClassification =
rstAssetClassification![AssetClassification]
Set nNode = objTree.Nodes.Add(KeyIndex, tvwChild, "ACL" & CInt
(rstAssetClassification!AssetClassificationID),
strAssetClassification, "ClassPic")
rstAssetClassification.MoveNext
Loop
rstLocations.MoveNext
Loop
SysCmd acSysCmdSetStatus, "Ok, we are all set your treeview is
ready to use"
ExitForm_Load:
Exit Sub
ErrForm_Load:
MsgBox Err.Description, vbCritical, "Form_Load"
Resume ExitForm_Load
End Sub
Rob said:
Hi Russ,
Here's a selection of articles regarding the treeview control:
The best example I've seen which illustrates the MS treeview control
and its capabilities is on Alex Dybenko's site, at
http://www.pointltd.com/Downloads/Details.asp?dlID=36
There's an article on using the MS Treeview control in one of Helen
Fedemma's Access Archon columns:
http://www.helenfeddema.com/access.htm - on the Archon page (which
opens from that link) download accarch52.zip. There's also an
article on using the MS Treeview wizard (formerly available as a
separate download for A87 - not sure if it's stilll available, or
works with later versions) in accarch53.zip. And, perhaps most
applicable to your current situation, an article on using a treeview
control as a record selector, at accarch103.zip.
For more references, see this page on Jeff Conrad's Access Junkie
site:
http://www.accessmvp.com/JConrad/accessjunkie/treeview.html
HTH,
Rob
Can any offer some advise / guidance on setting this up, seems to
more difficult then I thought?
[quoted text clipped - 41 lines]
Main Unit (I
select Main Unit , now see all Assets by ID)