How to pass existing subform records to another subform

How to pass existing subform records to another subform

Please let me know if you can provide assistance with the following problem:
  • I have a form that lists building materials.
  • Each material type has its own row where its general features are recorded.
  • Because each material is offered by more than one vendor, the vendors and their description and code for the material are listed in a subform within the material record.  All working properly.
  • The problem is on the ordering form, I have had difficulty extracting the vendor code and description on an Order Items subform.  I had to resort to the following code to extract the values - it's a bit of a hack :
selected_vendor = input.Vendor_lookup;
selected_item = input.Line_Items.Items_order;
list_a = list();
list_b = list();
i = 0;
//...............................................................
x = Materials_Form[ID == selected_item].Vendors_subform;
for each  y in x
{
list_a.add(y);
list_value = list_a.get(i);
list_b.add(list_value);
i = i + 1;
chosen_item = Materials_Form[ID = y];
vendor_id = y.Vendors_ID;
if(vendor_id == selected_vendor)
{
vendor_product_ID = y.ID;
vendor_code = y.Vendor_Code;
vendor_description = y.Vendor_Description;
vendor_price = y.Vendor_Cost_per_Unit;
}
}

row.Vendor_Product_Description=vendor_description;
row.Vendor_Code=vendor_code;
row.Cost=vendor_price;


This code produces a correct result for the first line item, but new line items for the same vendor duplicate the first line item vendor descriptive details even though the lookup field is pointing to a different product.  The second line quantity to total formula doesn't run.  Screenshots are available.

I'm n ew to Zoho Creator and this is my first application.  I'm not sure how to proceed to get subsequent line items to run the same routine.  Looking forward to hearing from you.