Hi again!
Yes it is. In several our applications is realized its. It's used comparatively difficult recursive function for creating of tree. Also table structure is developed especially for them (2 related fields in same table - unique field and field for entering of belongs). Of course it's possibly to solve it with related tables. This second way I'll describe as example from my application.
1. Tables' structure
XUNT - Unit labels
TypeUnitNo Long Primary
TypeUnitVersNo Integer Primary
TypeUnitName Text 50
XUNT - Sub Unit structure
TypeUnitNo Long Primary
TypeUnitVersNo Integer Primary
TypeUnitStrNo Integer Primary (Sequence number)
TypeSubUnitNo Long Primary
TypeSubUnitVersNo Integer Primary
SubUnitAmount Integer
Relations fields (ono to many) between tables are marked red. In such case are used fields for unit versions (complex structure, but it's possibly to simplify it - create tables without
VersNo fields (font
Italic))
2. Function for creating of tree:
Function UnitTree(blnTop As Boolean, trvTypeUnit As Object, strParent As String, strParentVer As String, strTypeUnitNo As String, strVer As String)
On Error GoTo Err_UnitTree
Dim strSQL As String
Dim strFrom As String
Dim strWhere As String
Dim NodX As Node
Dim strParentKey As String
Dim strKey As String
Dim i As Byte
Dim btyAmount As Byte
Dim rst As Recordset
Dim errCount As Byte
TryAgain:
strKey = "TU0000"
If blnTop = True Then
trvTypeUnit.Nodes.Clear
strSQL = "SELECT XUNT.TypeUnitNo, XUNT.TypeUnitVersNo, XUNT.TypeUnitName "
strFrom = "FROM XUNT "
strWhere = "WHERE XUNT.TypeUnitNo=" & strTypeUnitNo & " AND XUNT.TypeUnitVersNo=" & strVer
strSQL = strSQL & strFrom & strWhere & ";"
Set rst = CurrentDb.OpenRecordset(strSQL)
Set NodX = trvTypeUnit.Nodes.Add(, , strKey, CStr(rst(2)), "CLOSED", "SELECTED"

NodX.ExpandedImage = "OPEN"
End If
strParentKey = strKey
strSQL = "SELECT XUNT.TypeUnitNo, XUNT.TypeUnitVersNo, XUNT.TypeUnitName, XSTR.TypeUnitStrNo, XSTR.TypeSubUnitNo, XSTR.TypeSubUnitVersNo, XSTR.SubUnitAmount, XUNT_1.TypeUnitName "
strFrom = "FROM (XUNT LEFT JOIN XSTR ON (XUNT.TypeUnitVersNo = XSTR.TypeUnitVersNo) AND (XUNT.TypeUnitNo = XSTR.TypeUnitNo)) LEFT JOIN XUNT AS XUNT_1 ON (XSTR.TypeSubUnitVersNo = XUNT_1.TypeUnitVersNo) AND (XSTR.TypeSubUnitNo = XUNT_1.TypeUnitNo) "
strWhere = "WHERE XSTR.TypeSubUnitNo Is Not Null And XUNT.TypeUnitNo=" & strTypeUnitNo & " AND XUNT.TypeUnitVersNo=" & strVer
strSQL = strSQL & strFrom & strWhere & ";"
Set rst = CurrentDb.OpenRecordset(strSQL)
If Not rst.EOF Then
Do While Not rst.EOF
For i = 1 To rst(6)
strKey = "TU" & Format(CStr(trvTypeUnit.Nodes.Count + 1), "0000"

Set NodX = trvTypeUnit.Nodes.Add(strParentKey, 4, strKey, CStr(rst(7)), "CLOSED", "SELECTED"

NodX.ExpandedImage = "OPEN"
Call UnitTreeSub(False, trvTypeUnit, strKey, CStr(rst(4)), CStr(rst(5)))
Next i
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
trvTypeUnit.Nodes(1).Expanded = True
trvTypeUnit.Visible = True
Exit_UnitTree:
Exit Function
Err_UnitTree:
If Err.Number = -2147417848 Then
If errCount < 3 Then
GoTo TryAgain
End If
End If
End Function
Function UnitTreeSub(blnTop As Boolean, trvTypeUnit As Object, strParent As String, strTypeUnitNo As String, strVer As String)
Dim strSQL As String
Dim strFrom As String
Dim strWhere As String
Dim NodX As Node
Dim strParentKey As String
Dim strKey As String
Dim i As Byte
Dim btyAmount As Byte
Dim rst As Recordset
If blnTop = False Then
strSQL = "SELECT XUNT.TypeUnitNo, XUNT.TypeUnitVersNo, XUNT.TypeUnitName, XSTR.TypeUnitStrNo, XSTR.TypeSubUnitNo, XSTR.TypeSubUnitVersNo, XSTR.SubUnitAmount, XUNT_1.TypeUnitName "
strFrom = "FROM (XUNT LEFT JOIN XSTR ON (XUNT.TypeUnitVersNo = XSTR.TypeUnitVersNo) AND (XUNT.TypeUnitNo = XSTR.TypeUnitNo)) LEFT JOIN XUNT AS XUNT_1 ON (XSTR.TypeSubUnitVersNo = XUNT_1.TypeUnitVersNo) AND (XSTR.TypeSubUnitNo = XUNT_1.TypeUnitNo) "
strWhere = "WHERE XSTR.TypeSubUnitNo Is Not Null And XUNT.TypeUnitNo=" & strTypeUnitNo & " AND XUNT.TypeUnitVersNo=" & strVer
strSQL = strSQL & strFrom & strWhere & ";"
Set rst = CurrentDb.OpenRecordset(strSQL)
If Not rst.EOF Then
Do While Not rst.EOF
For i = 1 To rst(6)
strKey = "TU" & Format(CStr(trvTypeUnit.Nodes.Count + 1), "0000"

Set NodX = trvTypeUnit.Nodes.Add(strParent, 4, strKey, CStr(rst(7)), "CLOSED", "SELECTED"

NodX.ExpandedImage = "OPEN"
Call UnitTreeSub(False, trvTypeUnit, strKey, CStr(rst(4)), CStr(rst(5)))
Next i
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
End If
End Function
I'm sorry but now I have not so much time for detailed description. If you'll not make out how to run functions send me e-mail later.
Good luck!
Aivars
alaganovskis@hotmail.com