Code Error [Latha Accounts]

Code Error [Latha Accounts]

I some deluge code that I think will satisfy what I need from http://creator.zoho.com/latha/accounts/

Here is the code:
Tot_Credits_Paid_Jan = 0;
Tot_Debits_Paid_Jan = 0;
Tot_Credits_Paid_Feb = 0;
Tot_Debits_Paid_Feb = 0;
for each x in Accounts
{
    //to fetch the month from the Date field
    Month = x.InvoiceDate.getMonth();
    if (Month  ==  1)
    {
        Tot_Credits_Paid_Jan = (Tot_Credits_Paid_Jan  +  x.Credits_Paid);
        Tot_Debits_Paid_Jan = (Tot_Debits_Paid_Jan  +  x.Debits_Paid);
        // to fetch row from the Accounts_summary form with value of Month field as "Jan"
        MonthJan  =  Accounts_summary  [Month == "Jan"];
        MonthJan.Monthly_Debits_paid = Tot_Debits_Paid_Jan;
        MonthJan.Monthly_Credits_paid = Tot_Credits_Paid_Jan;
    }
    else if (Month  ==  2)
    {
        Tot_Credits_Paid_Feb = (Tot_Credits_Paid_Feb  +  x.Credits_Paid);
        Tot_Debits_Paid_Feb = (Tot_Debits_Paid_Feb  +  x.Debits_Paid);
        MonthFeb  =  Accounts_summary  [Month == "Feb"];
        MonthFeb.Monthly_Debits_paid = Tot_Debits_Paid_Feb;
        MonthFeb.Monthly_Credits_paid = Tot_Credits_Paid_Feb;
    }
}
































I tried to adapt it to my own db but it doesnt seem to be working and I cant for the life of me figure out why. I have set up a similar structure where the main table in this case "datos" is sending the information to "datosmensuales". I keep getting the error below. Any help would be greatly appreciated. I have opened the db to support.

I keep getting this error:

Error details:
Error occured while executing on success script.
Unable to update variable
Value for the field x.t_228989000000014015.Refereneci_228989000000014468 is null.


Code:
Tot_Charlas_E = 0;
Tot_Consejerias_E = 0;
Tot_VisitasDom_E = 0;
Tot_Referenecias_E = 0;
Tot_Ferias_E = 0;
Tot_Otros_E = 0;
Tot_TotaldeMujeres_E = 0;
Tot_DIUInsert_E = 0;
Tot_MedCap_E = 0;
Tot_EnfCap_E = 0;
Tot_Charlas_F = 0;
Tot_Consejerias_F = 0;
for each x in Datos
{
    //to fetch the month from the Date field
    Month = x.Fecha.getMonth();
    if (Month  ==  1)
    {
        Tot_Charlas_E = (Tot_Charlas_E  +  x.Charlas);
        Tot_Consejerias_E = (Tot_Consejerias_E  +  x.Consejerias);
        Tot_VisitasDom_E = (Tot_VisitasDom_E  +  x.VisitasDom);
        Tot_Referenecias_E = (Tot_Referenecias_E  +  x.Referenecias);
        Tot_Ferias_E = (Tot_Ferias_E  +  x.Ferias);
        Tot_Otros_E = (Tot_Otros_E  +  x.Otros);
        Tot_TotaldeMujeres_E = (Tot_TotaldeMujeres_E  +  x.TotaldeMujeres);
        Tot_DIUInsert_E = (Tot_DIUInsert_E  +  x.DIUInsert);
        Tot_MedCap_E = (Tot_MedCap_E  +  x.MedCap);
        Tot_EnfCap_E = (Tot_EnfCap_E  +  x.EnfCap);
        // to fetch row from the Accounts_summary form with value of Month field as "Jan"
        MonthJan  =  DatosMensuales  [Mes == "Enero"];
        MonthJan.CharlasSum = Tot_Charlas_E;
        MonthJan.ConsejeriasSum = Tot_Consejerias_E;
        MonthJan.VisitasDomSum = Tot_VisitasDom_E;
        MonthJan.RefereneciasSum = Tot_Referenecias_E;
        MonthJan.FeriasSum = Tot_Ferias_E;
        MonthJan.OtrosSum = Tot_Otros_E;
        MonthJan.TotaldeMujeresSum = Tot_TotaldeMujeres_E;
        MonthJan.DIUInsertSum = Tot_DIUInsert_E;
        MonthJan.MedCapSum = Tot_MedCap_E;
        MonthJan.EnfCapSum = Tot_EnfCap_E;
    }
    else if (Month  ==  2)
    {
        Tot_Charlas_F = (Tot_Charlas_F  +  x.Charlas);
        Tot_Consejerias_F = (Tot_Consejerias_F  +  x.Consejerias);
        // to fetch row from the Accounts_summary form with value of Month field as "Jan"
        MonthJan  =  DatosMensuales  [Mes == "Feb"];
        MonthJan.CharlasSum = Tot_Charlas_F;
        MonthJan.ConsejeriasSum = Tot_Consejerias_F;
    }
}