473,772 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11133
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.n et 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*********@nat pro.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.n et 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.n et wrote in
news:11******** ************@j3 3g2000cwa.googl egroups.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.OpenRecordse t(tblname)
'-------------------------------------------
' Set up source query
strSQL = "SELECT ProductStructur e.Parent_ITEM, " & vbNewLine _
& "child_Items.IT EM_KEY," & vbNewLine _
& "child_Items.IT EM_NAME," & vbNewLine _
& "ProductStructu re.Quantity," & vbNewLine _
& "ProductStructu re.UM," & vbNewLine

strSQL = strSQL & "FROM ProductStructur e INNER JOIN ITEM_Master
AS Child_Items " & vbNewLine _
& "ON (ProductStructu re.child_ITEM = child_Items.ITE M_KEY)"
& vbNewLine

strSQL = strSQL & "WHERE (ProductStructu re.Parent_ITEM) = '"

strSQL2 = "' ORDER BY Child_Items.ITE M_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.DeleteObj ect 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.OpenRecordse t(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******** ************@j3 3g2000cwa.googl egroups.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**@packairin c.com> wrote in
news:Ba******** ************@at henet.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.par t,nz(tblbom_5.p art,nz(tblbom_4 .part,
nz(tblbom_3.par t,nz(tblbom_2.p art,nz(tblbom_1 .part,
tblbom.part)))) )) AS PART,
nz(tblbom_6.qty ,1)*nz(tblbom_5 .qty,1)*nz(tblb om_4.qty,1)*
nz(tblbom_3.qty ,1)*,nz(tblbom_ 2.qty,1)*nz(tbl bom_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
2294
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 class, as in: def walk(self): """old-style recursive tree traversal""" child.do_something for child in childs:
10
5675
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. Not being a computer scientist, I find recursive functions to be frightening and unnatural. I'd appreciate if anyone can tell me the pythonic idiom to accomplish this. Thanks for your help,
2
2888
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 a sequence of spaces; recursive function 2 uses input to display ascending sequence of digits; likewise, recursive function 3 uses input to display descending sequence of digits. I have not followed the instructions completely regarding the...
7
567
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
2393
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 process if you want. The problem now is to make a Type list so I can specify more than one node at a time to "attach" a class to. I think I will be able to handle this but I want to run the code by you guys to see there are any major design...
4
9055
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. However, it is not as straightforward to determine the base address for my stack space. The approach I have taken is to save the address of an automatic variable in main( ), and assume this is a fairly good indicator of my base address. Then, I can...
9
3328
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
1959
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 made to the DB. However, I am trying to do the same thing within a stored procedure in SQL using recursive CTEs (I think the performance might be better) but I'm finding it really tough to craft the CTE. I would really appreciate if someone could...
18
4728
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: from pyparsing import * grammar = OneOrMore(Word(alphas)) + Literal('end') grammar.parseString('First Second Third end')
3
4243
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 reference, which means it is only collected by the mark-and-sweep collector, not by reference counting. Here is some code that demonstrates it: === def outer():
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6716
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.