I'll throw the first 20 lines at you for each table (they line up just fine for now, but there is a total of 820 or so entries in LineItems and I don't think you need that much, let me know if you need more).
LineItems Table:
"LineItem_ID","LineItem_Name","Sibling_Pos"
1,"Strategic Missile Systems",1
2,"Strategic Missile Systems Integration, Assembly, Test and Checkout",1
3,"Air Vehicle Equipment (AVE)/Flight Vehicle Equipment (FVE)",2
4,"AVE/FVE SEIT/PM and Support Equipment",1
5,"Integration, Assembly, Test, and Checkout",1
6,"Program Management",2
7,"Systems Engineering",3
8,"Training",4
9,"Data",5
10,"Operational/Site Activation",6
11,"Initial Spares/Repair Parts",7
12,"Logistics Support",8
13,"System Test and Evaluation",9
14,"Support Equipment",10
15,"Common Support Equipment",1
16,"Peculiar Support Equipment",2
17,"Depot Support Equipment/Rate Tooling",3
18,"Other SEIT/PM and Support Equipment",11
19,"Aero Structure (Non Stage Related)",2
20,"Stage 1-3 Interstage",3
WBS_LineItems table:
"LineItem_ID","Parent_ID","WBS_Category_ID"
1,,
2,1,
3,1,
4,3,
5,4,
6,4,
7,4,
8,4,
9,4,
10,4,
11,4,
12,4,
13,4,
14,4,
15,14,
16,14,
17,14,
18,4,
19,3,
20,3,
The temp table screen cap I gave you is built via recursive VBA and the WBS_Num column does not exist in the DB. That column is dynamically built when a form is open and is only present for the User. Below is the VBA used to build the table (if you wish
to critique it please feel free, but I do understand that such feedback is outside the scope of my current question. I'm just including it for clarity). The temp_WBS table is on the user interface side and is intended to be regularly emptied and filled.
Public Sub BuildWBSHeirarchy(Optional isStaging As Boolean = False, Optional WBS_ID As Long = -1, Optional dBase As Database, Optional wbsNumber As String = "", Optional indent As Integer = 0)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim q As String
If (dBase Is Nothing) Then
Set db = CurrentDb()
Else
Set db = dBase
End If
q = "SELECT WBS.LineItem_ID AS ID, LI.LineItem_Name AS Name, LI.Sibling_Pos " & _
"FROM WBS_LineItems AS WBS " & _
"INNER JOIN LineItems AS LI ON LI.LineItem_ID = WBS.LineItem_ID " & _
"WHERE WBS.Parent_ID " & IIf(WBS_ID = -1, "IS NULL", "= " & WBS_ID)
If (isStaging) Then
q = q & " " & _
"UNION " & _
"SELECT SWBS.LineItem_ID AS ID, SLI.LineItem_Name AS Name, SLI.Sibling_Pos " & _
"FROM staging_WBS_LineItems AS SWBS " & _
"INNER JOIN LineItems AS SLI ON SLI.LineItem_ID = SWBS.LineItem_ID " & _
"WHERE SWBS.Parent_ID " & IIf(WBS_ID = -1, "IS NULL", "= " & WBS_ID)
End If
q = q & _
" ORDER BY Sibling_Pos"
Set rs = db.OpenRecordset(q)
Do Until rs.EOF
'**Fix for top level items. (better way?)**
Dim ns As String
If (wbsNumber = "") Then
ns = rs![Sibling_Pos]
Else
ns = wbsNumber & "." & rs![Sibling_Pos]
End If
'**End Fix**
db.Execute ("INSERT INTO temp_WBS" _
& "(LineItem_ID, WBS_Num, Name) " _
& "Values (" & rs![ID] & ",'" & ns & "','" & Space(indent + 1) & rs![name] & "')")
BuildWBSHeirarchy isStaging, rs![ID], db, ns, indent + 3
rs.MoveNext
Loop
Set rs = Nothing
Set db = Nothing
End Sub