没有看到递归
程序代码:
Private Sub Command1_Click()
PN = Trim(Text1.Text)
If PN = "" Then
Exit Sub
End If
Assembly = PN
Conn.Execute ("Delete * from BOM_A")
If Rs.State = 1 Then
Rs.Close
End If
Rs.Open "Select * from BOM where [Assembly] = '" & PN & "'", Conn, 1, 1 ' BOM为上阶材料和下阶材料的对应关系表
If Not Rs.EOF Then
Rs.MoveFirst
Do While Not Rs.EOF
Component = Rs.Fields("Component")
Component_Type = Rs.Fields("Component_Type")
Usage = Rs.Fields("Usage")
Conn.Execute ("Insert into BOM_A Values('" & PN & "','" & Assembly & "','" & Component & "','" & Component_Type & "'," & Usage & ")") '--- BOM_A 为 A料的BOM表
Rs.MoveNext
Loop
Rs.Close
Else
MsgBox "没有找到材料BOM:" & Assembly
Rs.Close
Exit Sub
End If
Rs_Qty = 1
Do Until Rs_Qty = 0
Rs.Open "Select * from BOM_A where [Material] = '" & PN & "' and [Component_Type] <> 'RawPart' and [Component] not in (Select distinct [Assembly] from BOM_A)", Conn, 1, 1
Rs_Qty = Rs.RecordCount
If Rs_Qty <> 0 Then
StrSQL = "Insert into BOM_A Select * from (Select '" & PN & "' as [Material],A.[Component] as [Assembly],B.[Component],B.[Component_Type],B.[Usage] from (Select Distinct [Component] from BOM_A " & _
"where [Component_Type] <> 'RawPart' and [Component] not in (Select distinct [Assembly] from BOM_A)) as A Left join BOM B on A.[Component]=B.[Assembly])"
Conn.Execute (StrSQL)
Else
Rs.Close
Exit Do
End If
Rs.Close
Loop
Rs.Open "Select * from BOM_A where [Material] = '" & PN & "'", Conn, 1, 1
Set DataGrid1.DataSource = Rs
DataGrid1.Refresh
End Sub
[ 本帖最后由 owenlu1981 于 2014-3-19 23:05 编辑 ]










