Hello,
I am in a bit of a problem and I have spent few hours trying to figure it out, but I havent been able to get it to work.
Background Information
On a form, I have a subform (which contains the following fields:- Transaction Type (option :- receipt, cheque), Date (date), Description (text), Amount (decimal)). Also on the form, there is a field called 'Annual Allocation'. All, I had to do is look at all the Transaction type which are off type "Cheque" and add all of there 'Amount' fields. Once you have the totalsum of the Amounts field, compare it with 'Annual Allocation' field. If 'amount' is greater than 'annual allocation'. Throw an error.
Code:
IF Rec."Transaction Type" = Rec."Transaction Type"::Cheque THEN
BEGIN
lrecJob.GET(Rec."Job No.");
lrecConsumerDisbursement.SETCURRENTKEY("Transaction Type");
lrecConsumerDisbursement.SETRANGE("Job No.", Rec."Job No.");
lrecConsumerDisbursement.SETRANGE("Transaction Type", "Transaction Type"::Cheque);
lrecConsumerDisbursement.CALCSUMS(Amount);
TotalAmount := lrecConsumerDisbursement.Amount+ Rec.Amount;
IF lrecJob."Annual Allocation" < TotalAmount THEN
ERROR(NotEnoughFunds);
END;
Some of you guyz might be wondering why I added: rec.Amount to the Total Amount variable. That is because it never use to remember the new value that the user typed. That was just me trying to force it to remmeber the current value (and forget the last one) in the field.
This works most of the time. But Its does not have 100% success rate.
Its not working for the following case:
Lets say I added bunch of records to my subform of transaction type cheque. It will work, untill the Amount field is more than Annual Allocation, at which point it will throw me an error saying: not sufficient funds. At which point user has to change the value in the amount field so the total sum is less than annual allocation. However, even when the user changes the value, it remember the value i had previously (before the error mesage) and the value he/she just changed too, which gives me an even higher total amount, which throws an error all over again.
How can i make it forget the value i had previously (before the error message), so it only considers the new value and calculates the totalAmount all over again.
Screenshot to give you a better understanding.
http://screencast.com/t/xtrQUutmFpu3