'row' is invalid collection error

'row' is invalid collection error

I have a form and on this form I dragged in a subform from the buttons, then I added the below script to each of the subform fields that contribute to the Sub Total. All worked well. However then I decided that I needed the other type of subform where I have a linked field so I created a new form with the subform fields that I needed then added it to my main form with the linking. Then I added the below code to the Qnty field and clicked Save Script, and got the below error:  Error at line number : 1 
'row' is a invalid collection and update is not possible

How can I fix this?



row.Sub_Total = (row.Qnty  *  row.Price  +  row.Labor  -  row.Discount);
input.GrandTotal = 0.0;
for each item in Service
{
    input.GrandTotal = (input.GrandTotal  +  item.Sub_Total);
}


I have both subforms still on the Main Form. The Main form is called "Add Sale".


Iram