Problem setting values on new record in subform

I have a subform which contains a list of payments and dates. When the user proceeds to the next blank line on my subform, I populate the payment amount with the amount from the preceeding line and the date from the preceeding line plus 1 month … as follows :

IF BelowxRec THEN
BEGIN
IF (xRec.“Posting Date” <> 0D) AND (xRec.Amount <> 0)
AND (TotalLineAmount < PrepaymentHeader.“Prepayment Amount”) THEN
BEGIN
RemainingAmount := PrepaymentHeader.“Prepayment Amount” - TotalLineAmount;
“Posting Date” := CALCDATE(‘1M’,xRec.“Posting Date”);
IF xRec.Amount <= RemainingAmount THEN
Amount := xRec.Amount
ELSE
Amount := RemainingAmount
END;
END;

TotalLineAmount is a running total of the lines on the subform. This gets updated by the OnInsertRecord, OnModifyRecord and OnDeleteRecord triggers. PrepaymentHeader.“Prepayment Amount” is the maximum allowable value for TotalLineAmount, read from the mainform Sourcetable.

The code works, up to a point. When the user moves down to a blank line, the date and amount fields are populated correctly. But then the user cant proceed to create any more lines. The new line never gets inserted. If the user moves back up to the previous line, the newline disappears.

MultipleNewLines doesnt help …

Does anyone know what would help ?

… the code from my original post is in the OnNewRecord trigger of the subform.

May be the reason lies in your code in the OnInsertRecord - trigger of the Subform… - This trigger should return a TRUE to get the record inserted.

Thanks for the idea, but the code doesnt return TRUE or FALSE. The help says that TRUE is the default so I assume the insert should complete ok.

If I tab from one field of my subform table to the other, then the record becomes inserted. Is there any way to trigger the INSERT in code ?

Hi Bob_Up,

Have you had a look at how the Journal Forms do it and tried to replicate this?

T

I now have a working application, thanks to Bob from NY. The solution was to force the subform to switch between fields, in order to trigger an insert. This made use of Windows Script Host,

http://www.mibuso.com/forum/viewtopic.php?t=24355

Thanks to everybody who replied.

Bob