473,414 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Recursive BOM

Hello All,

I'm a middle-low level user of MS Access 2000. I'm trying to find a
solution to what appears to be a common problem. By browsing the net
and the groups, I've seen several posts and solutions to that problem
but I've not been able to find a ready to use query or module directly
working into MS Access.

The problem is the standard BOM problem.
I have a BOM structure setup in 2 tables:

tblParts:
PartID PK Number
Part Code Text
Part Description Text

tblBOM:
Parent Code Text
Child Code Text
QTY Number

And of course we can have an unlimited number of level in the BOMs.

Here's a 3 levels exemple:

tblPart
PartID Part Code Part Description
1 Finish1 Finished Part 1
2 Finish2 Finished Part 2
3 SemiFinished1 Semi Finished Part 1
4 SemiFinished2 Semi Finished Part 2
5 Component1 Component 1
6 Component2 Component 2
7 Component3 Component 3
8 Component4 Component 4

tblBOM
Parent Code Child Code QTY
SemiFinished1 Component1 1
SemiFinished2 Component1 1
SemiFinished1 Component2 3
Finish1 Component3 2
SemiFinished2 Component3 3
Finish2 Component4 3
Finish1 SemiFinished1 1
Finish2 SemiFinished1 4
Finish2 SemiFinished2 1

I'm trying to have a query that would give me for a given part, the
complete list of components whatever the number of levels in the BOM.

For exemple
Finish1 Component3 2
Finish1 Component2 3
Finish1 Component1 1

I've created a database with the 2 tables available at:
http://www.zembra.net/BOM.mdb

Any help to develop/integrate this query would be more than greatly
appreciated.

Thanks, Pascal

May 18 '06 #1
7 11108
Hello Pascal,

Access won't let you recurse a query, but you can wrote some code that
sets up an array of parts lists recordsets, then processes each single
parts list in a loop, opening the recordset for the relevant lower
level as it finds it.. The quantity for each entry is the product, not
the sum.

Once you have the full indented explosion, which looks like this
Level Item QTY QTYEXPL
0 Finish1 1 1
1 SemiFinished1 2 2
2 Component1 1 2
2 Component2 3 6
1 Component3 2 2

Just sum QTYEXPL on ITEM

May 18 '06 #2
you either need to explode the bom into a temporary table from which to
report on
or you can change your structure to use 'nested sets' (lots of google
info)

pa****@zembra.net wrote:
Hello All,

I'm a middle-low level user of MS Access 2000. I'm trying to find a
solution to what appears to be a common problem. By browsing the net
and the groups, I've seen several posts and solutions to that problem
but I've not been able to find a ready to use query or module directly
working into MS Access.

The problem is the standard BOM problem.
I have a BOM structure setup in 2 tables:

tblParts:
PartID PK Number
Part Code Text
Part Description Text

tblBOM:
Parent Code Text
Child Code Text
QTY Number

And of course we can have an unlimited number of level in the BOMs.

Here's a 3 levels exemple:

tblPart
PartID Part Code Part Description
1 Finish1 Finished Part 1
2 Finish2 Finished Part 2
3 SemiFinished1 Semi Finished Part 1
4 SemiFinished2 Semi Finished Part 2
5 Component1 Component 1
6 Component2 Component 2
7 Component3 Component 3
8 Component4 Component 4

tblBOM
Parent Code Child Code QTY
SemiFinished1 Component1 1
SemiFinished2 Component1 1
SemiFinished1 Component2 3
Finish1 Component3 2
SemiFinished2 Component3 3
Finish2 Component4 3
Finish1 SemiFinished1 1
Finish2 SemiFinished1 4
Finish2 SemiFinished2 1

I'm trying to have a query that would give me for a given part, the
complete list of components whatever the number of levels in the BOM.

For exemple
Finish1 Component3 2
Finish1 Component2 3
Finish1 Component1 1

I've created a database with the 2 tables available at:
http://www.zembra.net/BOM.mdb

Any help to develop/integrate this query would be more than greatly
appreciated.

Thanks, Pascal


May 18 '06 #3
Thanks a lot, this is exactly what I wouln need but I'm clueless when
it comes to writing this VB code. Is there a place where I can find
such code or is it possible toput that code into the group ?

Pascal

May 18 '06 #4
Thanks, I explored the nested sets solution, I found all the info
on-line including a sample mdb file but this won't address my needs as
in my case, the same component or semi-finished can be used in several
finished or semi-finished products....
le*********@natpro.com wrote:
you either need to explode the bom into a temporary table from which to
report on
or you can change your structure to use 'nested sets' (lots of google
info)

pa****@zembra.net wrote:
Hello All,

I'm a middle-low level user of MS Access 2000. I'm trying to find a
solution to what appears to be a common problem. By browsing the net
and the groups, I've seen several posts and solutions to that problem
but I've not been able to find a ready to use query or module directly
working into MS Access.

The problem is the standard BOM problem.
I have a BOM structure setup in 2 tables:

tblParts:
PartID PK Number
Part Code Text
Part Description Text

tblBOM:
Parent Code Text
Child Code Text
QTY Number

And of course we can have an unlimited number of level in the BOMs.

Here's a 3 levels exemple:

tblPart
PartID Part Code Part Description
1 Finish1 Finished Part 1
2 Finish2 Finished Part 2
3 SemiFinished1 Semi Finished Part 1
4 SemiFinished2 Semi Finished Part 2
5 Component1 Component 1
6 Component2 Component 2
7 Component3 Component 3
8 Component4 Component 4

tblBOM
Parent Code Child Code QTY
SemiFinished1 Component1 1
SemiFinished2 Component1 1
SemiFinished1 Component2 3
Finish1 Component3 2
SemiFinished2 Component3 3
Finish2 Component4 3
Finish1 SemiFinished1 1
Finish2 SemiFinished1 4
Finish2 SemiFinished2 1

I'm trying to have a query that would give me for a given part, the
complete list of components whatever the number of levels in the BOM.

For exemple
Finish1 Component3 2
Finish1 Component2 3
Finish1 Component1 1

I've created a database with the 2 tables available at:
http://www.zembra.net/BOM.mdb

Any help to develop/integrate this query would be more than greatly
appreciated.

Thanks, Pascal


May 18 '06 #5
pa****@zembra.net wrote in
news:11********************@j33g2000cwa.googlegrou ps.com:
Thanks a lot, this is exactly what I wouln need but I'm
clueless when it comes to writing this VB code. Is there a
place where I can find such code or is it possible toput that
code into the group ?

Pascal


Paste into a module. (watch for line wrapping)

Option Compare Database
Option Explicit
Dim strSQL As String
Dim strSQL2 As String
Dim db As Database
Dim rsSource(9) As Recordset
Dim rsTarget As Recordset
Dim tblname As String
Dim Seqno As Long

'============================
Public Sub Explode(ByVal RootItem As String)
'============================
On Error GoTo Explode_Error
Const LPN = 38
Seqno = 0
'--------------------------------------------
'Create a structure to receive the data
'--------------------------------------------
tblname = "XL" & RootItem

strSQL = "CREATE TABLE [" & tblname & "] (" _
& "Seqno long," & vbNewLine _
& "LLno integer," & vbNewLine _
& "Item text(" & LPN & ")," & vbNewLine _
& "Item_Name TEXT(64)," & vbNewLine _
& "Qty double," & vbNewLine _
& "UM text(6)," & vbNewLine _
& "Qty_Expl Double," & vbNewLine _
& "SeqNHA long," & vbNewLine _
& "CONSTRAINT seqno PRIMARY KEY (seqno)" & vbNewLine _
& ");"

DoCmd.RunSQL strSQL

Set db = CurrentDb
Set rsTarget = db.OpenRecordset(tblname)
'-------------------------------------------
' Set up source query
strSQL = "SELECT ProductStructure.Parent_ITEM, " & vbNewLine _
& "child_Items.ITEM_KEY," & vbNewLine _
& "child_Items.ITEM_NAME," & vbNewLine _
& "ProductStructure.Quantity," & vbNewLine _
& "ProductStructure.UM," & vbNewLine

strSQL = strSQL & "FROM ProductStructure INNER JOIN ITEM_Master
AS Child_Items " & vbNewLine _
& "ON (ProductStructure.child_ITEM = child_Items.ITEM_KEY)"
& vbNewLine

strSQL = strSQL & "WHERE (ProductStructure.Parent_ITEM) = '"

strSQL2 = "' ORDER BY Child_Items.ITEM_KEY;"

doOneRow RootItem, 0, 0, 1

Explode_exit:
rsTarget.Close
Set rsSource(9) = Nothing
Set rsTarget = Nothing
Set db = Nothing
Exit Sub

Explode_Error:
Select Case Err.Number
Case 3010 ' Table name exists
DoCmd.DeleteObject acTable, tblname
DoCmd.RunSQL strSQL ' repeat the call command
Resume Next
Case 3021 'no current record
Resume Next
Case Else
MsgBox "Please report this error to R Quintal ext xxxx" &
vbNewLine _
& Err.Number & " " & Err.Description, vbCritical
resume Explode_Exit
End Select
End Sub
'============================
Private Sub doOneRow(ByVal currentitem As String, ByVal LLno As
Long, ByVal SeqNHA As Variant, ByVal qtyNHA as double)
'============================
Dim vBkMark As Variant
Dim stCurrentRec As String
dim qtyExplode as double
Set rsSource(LLno) = db.OpenRecordset(strSQL & currentitem &
strSQL2, dbOpenDynaset)

Do Until rsSource(LLno).EOF
If rsSource(LLno).NoMatch Then
rsSource(LLno).Close
Exit Sub
Else
Seqno = Seqno + 1
QtyExplode = rsSource(LLno)!quantity * qtyNHA
With rsTarget
.AddNew
!Seqno = Seqno
!LLno = LLno
!Item = rsSource(LLno)!item_key
!item_name = rsSource(LLno)!item_name
!Qty = rsSource(LLno)!quantity
!UM = rsSource(LLno)!UM
!qty_expl = qtyExplode
!SeqNHA = SeqNHA
.Update
End With
stCurrentRec = rsSource(LLno)!item_key
vBkMark = rsSource(LLno).Bookmark

doOneRow stCurrentRec, LLno + 1, Seqno, qtyExplode

rsSource(LLno).Bookmark = vBkMark
rsSource(LLno).MoveNext
End If
Loop

End Sub

'================================== End of code

Modify as needed. Hope I didn't mangle too much while
transcribing.

Run from immediate window or code: Explode "Finish1"

--
Bob Quintal

PA is y I've altered my email address.
May 18 '06 #6
There is a query solution, it is messy and very limited in number of layers,
but it does work. Create a query linking in the BOM table for each layer of
the bill. Left Join the child to the parent part number. Use one more then
the max number of layers, if there is anything in the last column you will
need to edit the query.

SELECT tblBOM.[Part], tblBOM.Item, tblBOM.Qty, tblBOM_1.Item AS Item1,
tblBOM_1.Qty AS Qty1, tblBOM_2.Item AS Item2, tblBOM_2.Qty AS Qty2
FROM tblBOM LEFT JOIN (tblBOM AS tblBOM_1 LEFT JOIN tblBOM AS tblBOM_2 ON
tblBOM_1.Item = tblBOM_2.[Part]) ON tblBOM.Item = tblBOM_1.[Part]
WHERE (((tblBOM.[Part])="052542"));

You will end up with the following output.

PART ITEM QTY ITEM1 QTY1 ITEM2 QTY2
052542 221326 1 null null null
null
052542 056621 2 030024 3 null null
052542 056623 3 030029 2 082293 4

Sum this up in a 2nd query

PART ITEM Total QTY
052542 221326 1
052542 056621 0
052542 030024 6
052542 056623 0
052542 030029 0
052542 082293 24

As you see the 1st query will be very large, and the 2nd query will need a
complex iif statement to add up the quantity. Which is why a VB procedure
may be easer to learn and implement.
<pa****@zembra.net> wrote in message
news:11********************@j33g2000cwa.googlegrou ps.com...
Thanks a lot, this is exactly what I wouln need but I'm clueless when
it comes to writing this VB code. Is there a place where I can find
such code or is it possible toput that code into the group ?

Pascal

May 19 '06 #7
"paii, Ron" <pa**@packairinc.com> wrote in
news:Ba********************@athenet.net:
There is a query solution, it is messy and very limited in
number of layers, but it does work. Create a query linking in
the BOM table for each layer of the bill. Left Join the child
to the parent part number. Use one more then the max number of
layers, if there is anything in the last column you will need
to edit the query.

SELECT tblBOM.[Part], tblBOM.Item, tblBOM.Qty, tblBOM_1.Item
AS Item1, tblBOM_1.Qty AS Qty1, tblBOM_2.Item AS Item2,
tblBOM_2.Qty AS Qty2 FROM tblBOM LEFT JOIN (tblBOM AS tblBOM_1
LEFT JOIN tblBOM AS tblBOM_2 ON tblBOM_1.Item =
tblBOM_2.[Part]) ON tblBOM.Item = tblBOM_1.[Part] WHERE
(((tblBOM.[Part])="052542"));

You can use nested nz() functions to return just the pn for the
lowest level part number, but you need all the non-null
quantities to multiply out.

SELECT nz(tblbom_6.part,nz(tblbom_5.part,nz(tblbom_4.part ,
nz(tblbom_3.part,nz(tblbom_2.part,nz(tblbom_1.part ,
tblbom.part)))))) AS PART,
nz(tblbom_6.qty,1)*nz(tblbom_5.qty,1)*nz(tblbom_4. qty,1)*
nz(tblbom_3.qty,1)*,nz(tblbom_2.qty,1)*nz(tblbom_1 .qty,1 AS
rowQTY

The second query then is simplified to a standard summation
query.

I heard today that the BOM for the Space Station is 91 levels.

No way I'm gonna write that query!
--
Bob Quintal

PA is y I've altered my email address.
May 19 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Carlos Ribeiro | last post by:
Hello all, Here I am using some deeply nested, tree-like data structures. In some situations I need to traverse the tree; the old-style way to do it is to write a recursive method on the node...
10
by: Steve Goldman | last post by:
Hi, I am trying to come up with a way to develop all n-length permutations of a given list of values. The short function below seems to work, but I can't help thinking there's a better way. ...
2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
7
by: Jon Slaughter | last post by:
#pragma once #include <vector> class empty_class { }; template <int _I, int _J, class _element, class _property> class RDES_T {
1
by: Jon Slaughter | last post by:
I've managed to put together a template class that basicaly creates a recursive tree that lets you easily specify the "base" class of that tree and and ending notes and lets you stop the recursive...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
9
by: seberino | last post by:
I'm a compiler newbie and curious if Python grammar is able to be parsed by a recursive descent parser or if it requires a more powerful algorithm. Chris
0
by: champ1979 | last post by:
I wrote an algorithm to get all the relatives of a person in a family tree. I'm basically getting all the users from the DB and am doing the recursive logic in code, so that there is only 1 call...
18
by: Just Another Victim of the Ambient Morality | last post by:
Is pyparsing really a recursive descent parser? I ask this because there are grammars it can't parse that my recursive descent parser would parse, should I have written one. For instance: ...
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.