I have a composition of assembly units described in table tblComposition like this:
+-------+--------+----------+
| Child | Parent | Quantity |
+-------+--------+----------+
| 111 | 11 | 1 |
| 112 | 11 | 4 |
| 113 | 11 | 1 |
| 211 | 21 | 3 |
| 222 | 22 | 5 |
| 21 | 2 | 1 |
| 22 | 2 | 3 |
| 11 | 1 | 1 |
| 12 | 1 | 1 |
| 1 | 1 | 1 |
| 2 | 2 | 1 |
+-------+--------+----------+
That means that 5 parts number 222 is assembled in unit 22, and then 3 units 22 are is assembled in product 2. The nesting can be arbitrarily large.
If I define then production plan for next day in tblProducts:
+---------+------+
| Product | Plan |
+---------+------+
| 1 | 123 |
| 2 | 456 |
+---------+------+
Is there any SQL query or VBA code to acheve automatic calculation of plan for manufacturing child subassemblies and parts? So I could have the following result:
+-------+----------+
| Child | Plan |
+-------+----------+
| 111 | 123 |
| 112 | 492 |
| 113 | 123 |
| 211 | 1368 |
| 222 | 6840 |
| 21 | 456 |
| 22 | 1368 |
| 11 | 123 |
| 12 | 123 |
| 1 | 123 |
| 2 | 456 |
+-------+----------+