Hi,
So I have this database and I am trying to create a way to update a subform using criteria from the combox in the form. I have been thinking about how to go around accomplishing this and couldn't make it work using the queries (I might be wrong). I believe a VBA of some sort might be required to accomplish what I need to be done.
So let me start by explaining what I have. I have 2 tables linked to my database using ODBC. So I have 2 append queries to download the data into my 2 tables below.
Table 1 has:
- CPN
- ITEM_NBR
- FIRST_COMPONENT
Table 2 has:
- ID
- CP_PN
- CP_ITEM_NBR
- NEXT_COMP_NBR
- ITEM_NBR
What I am trying to create is a 3rd table which will house the parent item number along with the corresponding child item numbers. Below is an example of how Table 3 should look like
Table 3
PARENT_NBR CHILD_NBR
12345 34567
12345 g6739
12345 0896756
12345 9677383
98765 674937
98765 673938
98765 34567
etc...etc....
So this is were it gets tricky and complex on how to make table 3 by using table 1 & 2
Step1. So take an "ITEM_NBR" (PARENT_NBR) from Table 1 and combine the numbers found in the columns "CPN" and "FIRST_COMPONENT" that corresponds to the chosen "ITEM_NBR", this number will be used to search the "ID" column in table 2.
Step2. Once we have a match then we will copy the value in "CP_ITEM_NBR" in table 2 to be the first "CHILD_NBR" in table 3
Step3. At the same time you take the number in "CP_CPN" column in table 2 that corresponds to the "CP_ITEM_NBR" and use it to search the "CPN" column in Table 1 to see if there is a value/number in the "FIRST_COMPONENT" field corresponding to the "CPN" number you used.
Step4. You again take the "CPN" used in Step3 and combine it with the corresponding "FIRST_COMPONENT" (if it is not NULL) number to create a number that will be used to search the "ID" column in table 2.
Step5. Once we have a match then we will copy the value in "CP_ITEM_NBR" in table 2 to be the next "CHILD_NBR" in table 3
Step6. Repeat Step3, Step4 and Step5 till you reach a point where the "FIRST_COMPONENT" field in Table 1 is NULL and you cant combine the numbers per Step4.
While doing all the above steps the VBA should be also doing the below steps
Step7. VBA to check "NEXT_COMP_NBR" field in Table 2 if NULL. If not Null then do the following"
Step8. Take first 5 digits of "NEXT_COMP_NBR" and search the "CP_CPN" column in Table 2. IF match found then copy corresponding "CP_ITEM_NBR" number to be the next "CHILD_NBR" in table 3
Step9. Repeat Step8. till "NEXT_COMP_NBR" is NULL. Stop
Once all the above steps are completed that means the "PARENT_NBR" has all the corresponding "CHILD_NBR" in table 3
Hope my explanation make sense.
Any light or help on this is greatly appreciated
Thanks
RB
So I have this database and I am trying to create a way to update a subform using criteria from the combox in the form. I have been thinking about how to go around accomplishing this and couldn't make it work using the queries (I might be wrong). I believe a VBA of some sort might be required to accomplish what I need to be done.
So let me start by explaining what I have. I have 2 tables linked to my database using ODBC. So I have 2 append queries to download the data into my 2 tables below.
Table 1 has:
- CPN
- ITEM_NBR
- FIRST_COMPONENT
Table 2 has:
- ID
- CP_PN
- CP_ITEM_NBR
- NEXT_COMP_NBR
- ITEM_NBR
What I am trying to create is a 3rd table which will house the parent item number along with the corresponding child item numbers. Below is an example of how Table 3 should look like
Table 3
PARENT_NBR CHILD_NBR
12345 34567
12345 g6739
12345 0896756
12345 9677383
98765 674937
98765 673938
98765 34567
etc...etc....
So this is were it gets tricky and complex on how to make table 3 by using table 1 & 2
Step1. So take an "ITEM_NBR" (PARENT_NBR) from Table 1 and combine the numbers found in the columns "CPN" and "FIRST_COMPONENT" that corresponds to the chosen "ITEM_NBR", this number will be used to search the "ID" column in table 2.
Step2. Once we have a match then we will copy the value in "CP_ITEM_NBR" in table 2 to be the first "CHILD_NBR" in table 3
Step3. At the same time you take the number in "CP_CPN" column in table 2 that corresponds to the "CP_ITEM_NBR" and use it to search the "CPN" column in Table 1 to see if there is a value/number in the "FIRST_COMPONENT" field corresponding to the "CPN" number you used.
Step4. You again take the "CPN" used in Step3 and combine it with the corresponding "FIRST_COMPONENT" (if it is not NULL) number to create a number that will be used to search the "ID" column in table 2.
Step5. Once we have a match then we will copy the value in "CP_ITEM_NBR" in table 2 to be the next "CHILD_NBR" in table 3
Step6. Repeat Step3, Step4 and Step5 till you reach a point where the "FIRST_COMPONENT" field in Table 1 is NULL and you cant combine the numbers per Step4.
While doing all the above steps the VBA should be also doing the below steps
Step7. VBA to check "NEXT_COMP_NBR" field in Table 2 if NULL. If not Null then do the following"
Step8. Take first 5 digits of "NEXT_COMP_NBR" and search the "CP_CPN" column in Table 2. IF match found then copy corresponding "CP_ITEM_NBR" number to be the next "CHILD_NBR" in table 3
Step9. Repeat Step8. till "NEXT_COMP_NBR" is NULL. Stop
Once all the above steps are completed that means the "PARENT_NBR" has all the corresponding "CHILD_NBR" in table 3
Hope my explanation make sense.
Any light or help on this is greatly appreciated
Thanks
RB