VBA Required to append different rows (1 Viewer)

anilvaghela

Registered User.
Local time
Today, 16:54
Joined
Sep 10, 2008
Messages
12
hello...

I have a database which consists of 5 tables....

each table has the same fields but they are all linked.

Table 5 - Is joined by using the parent_id field which is linked to the unique_id on Table 4

And so on.... till Table 1.

Table 1 has data at level 1 on a hierarchy. So you will have for example 5 records in here. Which have its unique_id.

Table 2 will have for example 30 records which are grouped into the 5 records in Table 1. This is linked by the parent_id on Table 2 which is joined to unique_id on Table 1.

And so on for Table 3 which is joined to Table 2 and Table 4 joined to Table 3 and Table 5 joined to Table 4.

This is done and works fine.

But I want to be able to APPEND 1 of the 5 records first from Table 1 into a Main Table. Then go to Table 2 and APPEND only the FIRST Record which matches the unique_id from the record we appended from Table 1.

Then go to Table 3, 4 and then 5.

Then loop and go back to Table 2 not Table 1 as there maybe more records under Table 2 which maybe linked to the first record we appended from Table 1 and continue the same process... BUT IF not then Return to Table 1.... and so on!!!

.........................................................


It would be a great help if someone can help me as I am truly stuck!

Thanks!

:)
 

Guus2005

AWF VIP
Local time
Today, 17:54
Joined
Jun 26, 2007
Messages
2,641
Your database design could be a lot easier. You only need two tables.

Suppose you create a car. A car has an engine, an engine has a dynamo a dynamo has bolts and screws so does the engine, so does the car.

You need one table to store the Parts. such as bolts, screws, engine, wheels and so on.
you need one table to build your car: Product

In the Parts table you have the following fields: ID, description, ...
In the Products table you have the following fields: ParentID, ChildID

Now you can create your queries.

HTH:D
 

anilvaghela

Registered User.
Local time
Today, 16:54
Joined
Sep 10, 2008
Messages
12
Thanks for that....

But how in queries to i determine what i want to do..... which is basically take the first part and find other parts from level 2,3,4 and 5 and then append them ....then loop through it again and append another group......
 

Guus2005

AWF VIP
Local time
Today, 17:54
Joined
Jun 26, 2007
Messages
2,641
You will have to be creative on this one. You have to create a recursive function

pseudocode:
Code:
sub RecursiveTreeview(id)
  open a recordset based on the id
  does this parent have any children
     RecursiveTreeview(childID)
end sub
HTH:D
 

anilvaghela

Registered User.
Local time
Today, 16:54
Joined
Sep 10, 2008
Messages
12
Thanks.... i guess i can get my skates on from this point.....

Thanks again!!
 

Users who are viewing this thread

Top Bottom