mHi Bob,
The link that you send me has a link to a BOM.mdb attached but it
does not work. I think the owner removed it as the link dates from
May 2006. Would you still have it somewhere and could I retrieve
it somehow?
Thank you in advance,
Kind regards,
Elena
The link I posted is to a message with code, The one david posted is
to a .mdb, it's
http://www.mvps.org/access/modules/mdl0027.htm
The code is still on Google, I just copied it and pasted here for
you.
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(99) 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
padded.
Seqno = 0
'--------------------------------------------
'Create a structure to receive the data
'--------------------------------------------
tblname = "XL" & RootItem
strSQL = "CREATE TABLE [" & tblname & "] (" _
& "Seqno long," & vbNewLine _
& "LLno integer," & vbNewLine _
& "Item text(38)," & 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
Resume
Case 3021 'no current record
Resume Next
Case Else
MsgBox "Please report this error to R Quintal" &
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 "Partno"
Bob Quintal said:
http://groups.google.com/group/comp.databases.ms-
access/browse_frm/thread/297c01f1d5257aef/818b9d061280179e?
lnk=gst&q=explosion+Quintal&rnum=2#818b9d061280179e
Is code that explodes a BOM from a Product Structure table
Parent_item, ChildItem, QtyPer, etc
And an Items Table
Item, Item_Name, UnitOfMeasure, etc.