Options

Form and temporary table

clemboclembo Member Posts: 122
I have build a Tabular-Type Form binded to a temporary table.
User can insert in form some record. In the header form I have a textbox in which I want to show total amount (sum of amount field of all row).
How can I do it?

Comments

  • Options
    vijay_gvijay_g Member Posts: 884
    if you are able to calculate value of all rows for that text box then see how to update header form through line form.
    here is many help search forum.
  • Options
    veerendraveerendra Member Posts: 66
    You can write code to consider all the records in the temporary table while INSERT, MODIFY and DELETE and try to find out the sum value and update the form.
    Veerendra Ch.
    http://midynav.blogspot.com/ (Microsoft Dynamics Navision)
  • Options
    kinekine Member Posts: 12,562
    Just call function defined on subform from the main form which will calc the sum for you...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    clemboclembo Member Posts: 122
    I try to explain better:

    my table is:

    10 "Line No." Integer (Primary Key)
    20 "Description" Text
    30 "Amount" Decimal

    In my form property Autosplitkey=Yes
    No subform!

    In the Header I show several textbox (binded with some variable).
    One of this textbox must to show Total Amount (sum all rows).
    In this textbox I insert function called CalcTotalAmount.

    This is the code:

    IF Rec.FIND('-') THEN
    REPEAT
    TotalAmount := TotalAmount + Amount;
    UNTIL NEXT=0;

    EXIT(TotalAmount);

    When I run the form and try to insert more than first record:

    Error: Tablexxx (my table) "Line no." '10000' already exists.

    How I solve it? ](*,)
  • Options
    kinekine Member Posts: 12,562
    1) The problem is that you are looping through REC thus changing the position "in background"...
    2) Try to restore the original Rec after the loop (backup it at beginning and restore it after that just by :=)
    RecBackup := Rec;
    IF Rec.FIND('-') THEN
    REPEAT
    TotalAmount := TotalAmount + Amount;
    UNTIL NEXT=0;
    
    Rec := RecBackup;
    EXIT(TotalAmount);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    clemboclembo Member Posts: 122
    Great! Thank you =D>
Sign In or Register to comment.