BenFranske
New member
- Local time
- Today, 16:29
- Joined
- Jun 22, 2009
- Messages
- 2
Hi, I have the need to create the equivalent of a WHILE EXISTS SQL loop in Access and am thinking there should be a way to do this with some VBA code.
Some background: I'm working on a family tree database so each record (back to the root) has a parent record in the same table creating a hierarchical tree. To make things easier to work with, sort, etc. I have created lineage and generation fields which show the parents back to the root. This is based on the "More Trees & Hierarchies in SQL" article on the SQLTeam website.
Right now I'm trying to write update triggers in VBA so that if changes are made or new records added the lineage is automatically calclulated and entered into the table. Sample code is available at the SQLTeam site but it takes advantage of the WHILE EXISTS SQL command which is unsupported in Access. I need to find an equvalant way of doing things in VBA/Access.
The bottom line: I need to run this query:
Until no records are returned by:
in other words until all records have a generation. The code proposed by the SQLTeam article would look like:
but this obviously won't work in Access.
Any ideas about how to accomplish the same thing in Access/VBA?
Some background: I'm working on a family tree database so each record (back to the root) has a parent record in the same table creating a hierarchical tree. To make things easier to work with, sort, etc. I have created lineage and generation fields which show the parents back to the root. This is based on the "More Trees & Hierarchies in SQL" article on the SQLTeam website.
Right now I'm trying to write update triggers in VBA so that if changes are made or new records added the lineage is automatically calclulated and entered into the table. Sample code is available at the SQLTeam site but it takes advantage of the WHILE EXISTS SQL command which is unsupported in Access. I need to find an equvalant way of doing things in VBA/Access.
The bottom line: I need to run this query:
Code:
UPDATE Households AS T INNER JOIN Households AS P ON T.Relatives_Parents=P.GED_Family_ID SET T.Generation = P.Generation+1,
T.Relatives_Lineage = P.Relatives_Lineage+Ltrim(T.Relatives_Parents)+'/'
WHERE P.Generation>=0
And P.Relatives_Lineage Is Not Null
And T.Generation Is Null;
Code:
SELECT * FROM Households WHERE Households.Generation
Code:
WHILE EXISTS (SELECT * FROM Households WHERE Households.Generation Is Null)
UPDATE Households AS T INNER JOIN Households AS P ON T.Relatives_Parents=P.GED_Family_ID SET T.Generation = P.Generation+1,
T.Relatives_Lineage = P.Relatives_Lineage+Ltrim(T.Relatives_Parents)+'/'
WHERE P.Generation>=0
And P.Relatives_Lineage Is Not Null
And T.Generation Is Null;
Any ideas about how to accomplish the same thing in Access/VBA?
Last edited: