By the by I have being able to get the previous record I want. This is how I do it: created an “Entry No.” in the table as integer and auto-increment and use the code below:
EntryNo := “Entry No.” -1;
BenefitsKey.SETRANGE(“Entry No.”,EntryNo);
BenefitsKey.SETRANGE(“Employee #”,Cont.“Employee No.”);
IF BenefitsKey.FIND(’-’)
THEN BEGIN
OpeningBalance := BenefitsKey.ClosingBalance;
END;
Its working perfect and calculating properly. The only problem I have now is the automated calculation only works On Modify Trigger and not after validating the last insert field.
Below is the whole code for reference:
Cont.SETRANGE(“Employee No.”,“Employee #”);
Cont.SETRANGE(“From Date”,“Period Start”,“Period End”);
Cont.SETFILTER(“From Date”,’>=%1’,“Period Start”);
Cont.SETFILTER(“To Date”,’<=%1’,“Period End”);
//Code to Count Months
IF (“Period Start” <> 0D) AND (“Period End” > “Period Start”) THEN BEGIN
Calendar.RESET;
Calendar.SETRANGE(“Period Type”,Calendar.“Period Type”::Month);
Calendar.SETRANGE(“Period Start”,“Period Start”,“Period End”);
Months := Calendar.COUNT;
END ELSE
Months := 0;
// Code Ends above.
IF Cont.FIND(’-’)
THEN BEGIN
TotalAmount := Cont.Quantity;
IF Cont.NEXT <> 0
THEN
REPEAT
TotalAmount := TotalAmount + Cont.Quantity;
UNTIL Cont.NEXT = 0;
END;
IntCredit := (TotalAmount * Rate * Months)/24;
CurrAccTotal := IntCredit + TotalAmount;
EntryNo := “Entry No.” -1;
BenefitsKey.SETRANGE(“Entry No.”,EntryNo);
BenefitsKey.SETRANGE(“Employee #”,Cont.“Employee No.”);
IF BenefitsKey.FIND(’-’)
THEN BEGIN
OpeningBalance := BenefitsKey.ClosingBalance;
END;
OpIntCredit := OpeningBalance * Rate;
ClosingBalance := OpIntCredit + OpeningBalance + CurrAccTotal;
Any ideas welcome Please!