Problem Setting Values on New Record in Subform

bob_upbob_up Member Posts: 155
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 with the date from the previous line plus 1 month.

I have added the following code to the OnNewRecord trigger :

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, 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.

Autosplitkey is TRUE.

MultipleNewLines and DelayedInsert are both FALSE and changing their values doesnt make any difference ...

Comments

  • krikikriki Member, Moderator Posts: 9,110
    The user needs to change something for the record to be saved.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • bob_upbob_up Member Posts: 155
    Can I 'trick' the form into updating the table ? Can I make it think the data has been changed ?
  • bob_upbob_up Member Posts: 155
    It appears that all I need to do is to tab from one field to the other on the screen and the INSERT is triggered. Is there no way to trigger the INSERT in code ?
  • SavatageSavatage Member Posts: 7,142
    Do you want to use a Confim message like

    "Would you like to insert a new line" Yes/No or would that be too annoying?
  • bob_upbob_up Member Posts: 155
    I'm not sure I understand your suggestion. The spec. for this form says that, if the user moves to a new line, that date and amount fields on the new line will default to those from the previous line. If these defaults are ok, the user can move immediately to the next blank line and the processing will be repeated, up to a total amount which is defined on the mainform. Unfortunately, it seems that the form wont insert the new record if there has been no keyboard or mouse activity. Frutratingly, just moving from one field to another is enough to trigger the insert.

    Is there some way that a confirm message could help ? I tried adding an INSERT statement to the OnNewRecord trigger, but that trigger is not within a 'write transaction' ... ie, you cant update the database from there.

    Thanks for your suggestion though.
  • SavatageSavatage Member Posts: 7,142
    i was thinking adding a confirm and on confirm of yes it would

    currform update or table insert command would run

    IF CONFIRM('Would You Like To Add A New Line?',TRUE)
    THEN blag blah blah

    sombody is going to have to click something somewhere - even if it's just some phoney boolean field on the line.
  • bob_upbob_up Member Posts: 155
    Thanks for replying, Harry. I'm sorry but would you please clarify this further. Is the confirm prompt just to generate a click or a keypress or are you saying we would also need to do some processing after the confirm, such as an insert ? If we need to do more processing I think we would arrive in another dead end, because you cant perform an insert from the OnNewRecord trigger. I tried variations on Currform.UPDATE from that trigger too, to no avail :( Unless you can think of a different trigger from which to perform the insert.

    We are fighting a battle to win over a key individual at a new client. They have just migrated from another system and are complaining that certain functions within Dynamics are much more 'long-winded'. So I am trying to give them comparable functionality to their old system.

    As you suspected, I dont think the prompt on each new line is going to be impress them.

    That will teach me !! I assumed "Anything that old system can do, Dynamics can do better ...".
  • BobNYBobNY Member Posts: 3
    Try using windows script hosting to trigger a keyboard action such as tab.

    1. create automation variable WshShell using automation server Windows Script Host Object Model, WshShell class

    2. Code...
    OnNewRecord trigger:

    CLEAR(WshShell);
    CREATE(WshShell);
    WshShell.SendKeys('{HOME}');
    WshShell.SendKeys('{TAB}');
    Regards,
    Bob
    NY
  • bob_upbob_up Member Posts: 155
    Bob

    Problem solved =D> That worked a treat.

    I know with some automation objects there can be a problem with compiling objects on site. Is Windows Script Hosting pretty universal ?

    Thank you

    Bob :D
  • BobNYBobNY Member Posts: 3
    Bob,

    To the best of my knowledge, Windows script hosting is pretty universal and is included with any Windows os.

    yw
    Bob
    Regards,
    Bob
    NY
Sign In or Register to comment.