I'm working on a loop until statement (see below). My problem is that with the record this loop is working from, it should run 3 times, but it is only running one time and then stopping. Can anyone see what I did wrong?
[tt]
AloopStop = "N"
Do Until AloopStop = "Y"
If levelNum = 25 Then AloopStop = "Y"
If DCount("fcomponent", "inboms", "fparent IN (SELECT fcomponent FROM tblBomTemp WHERE levelNum = """ & levelNum & """)") = 0 Then AloopStop = "Y"
DoCmd.RunSQL "INSERT INTO tblBomTemp ( levelNum, MarkNum, fcomponent, fcompudrev, fitem, fparent, fcparudrev, fqty, fbommemo, cfacilityid, valEAinmast, valEAinvend, fdescript, fsource, fcpurchase )SELECT " & levelNum + 1 & " AS [Level], [tblBomTemp].[MarkNum] & '.' & Right([dbo_inboms].[fitem],3) AS MarkNumn, dbo_inboms.fcomponent, dbo_inboms.fcompudrev, Right([dbo_inboms].[fitem],3) AS Item, dbo_inboms.fparent, dbo_inboms.fcparudrev, dbo_inboms.fqty, dbo_inboms.fbommemo, dbo_inboms.cfacilityid, dbo_inmast.favgcost, qryLastPO.fvlastpc, dbo_inmast.fdescript, dbo_inmast.fsource, dbo_inmast.fcpurchase FROM ((dbo_inboms LEFT JOIN dbo_inmast ON dbo_inboms.fcomponent = dbo_inmast.fpartno) LEFT JOIN qryLastPO ON dbo_inboms.fcomponent = qryLastPO.fpartno) INNER JOIN tblBomTemp ON dbo_inboms.fparent = tblBomTemp.fcomponent WHERE (((tblBomTemp.levelNum)=" & levelNum & "));"
levelNum = levelNum + 1
Loop[/tt]
To clarify what I tried to write the loop to do, this loop runs after a set of records is entered into tblBomTemp. The queries in the loop look at tblBomTemp and compare it to the original data. For each item that has been added to tblBomTemp which has a "levelNum" that matches the current levelNum variable, it finds all records in the original data that list that component as a parent. These records are then inserted into tblBomTemp with their levelNum set to one higher. The levelNum variable is then raised to the next level, and it loops.
At the beginning of the loop, It checks if too many levels have passed and if there are no records to pull matching the above requirements. In either case, it will stop the loop. It appears, however, that it runs through the loop code one time, but then does not move on to pulling and inserting the level 3 and then level 4 data - which I have confirmed exists in the original tables.
Cheryl dc Kern
[tt]
AloopStop = "N"
Do Until AloopStop = "Y"
If levelNum = 25 Then AloopStop = "Y"
If DCount("fcomponent", "inboms", "fparent IN (SELECT fcomponent FROM tblBomTemp WHERE levelNum = """ & levelNum & """)") = 0 Then AloopStop = "Y"
DoCmd.RunSQL "INSERT INTO tblBomTemp ( levelNum, MarkNum, fcomponent, fcompudrev, fitem, fparent, fcparudrev, fqty, fbommemo, cfacilityid, valEAinmast, valEAinvend, fdescript, fsource, fcpurchase )SELECT " & levelNum + 1 & " AS [Level], [tblBomTemp].[MarkNum] & '.' & Right([dbo_inboms].[fitem],3) AS MarkNumn, dbo_inboms.fcomponent, dbo_inboms.fcompudrev, Right([dbo_inboms].[fitem],3) AS Item, dbo_inboms.fparent, dbo_inboms.fcparudrev, dbo_inboms.fqty, dbo_inboms.fbommemo, dbo_inboms.cfacilityid, dbo_inmast.favgcost, qryLastPO.fvlastpc, dbo_inmast.fdescript, dbo_inmast.fsource, dbo_inmast.fcpurchase FROM ((dbo_inboms LEFT JOIN dbo_inmast ON dbo_inboms.fcomponent = dbo_inmast.fpartno) LEFT JOIN qryLastPO ON dbo_inboms.fcomponent = qryLastPO.fpartno) INNER JOIN tblBomTemp ON dbo_inboms.fparent = tblBomTemp.fcomponent WHERE (((tblBomTemp.levelNum)=" & levelNum & "));"
levelNum = levelNum + 1
Loop[/tt]
To clarify what I tried to write the loop to do, this loop runs after a set of records is entered into tblBomTemp. The queries in the loop look at tblBomTemp and compare it to the original data. For each item that has been added to tblBomTemp which has a "levelNum" that matches the current levelNum variable, it finds all records in the original data that list that component as a parent. These records are then inserted into tblBomTemp with their levelNum set to one higher. The levelNum variable is then raised to the next level, and it loops.
At the beginning of the loop, It checks if too many levels have passed and if there are no records to pull matching the above requirements. In either case, it will stop the loop. It appears, however, that it runs through the loop code one time, but then does not move on to pulling and inserting the level 3 and then level 4 data - which I have confirmed exists in the original tables.
Cheryl dc Kern