Refresh Form from Subform

karlkarl Member Posts: 22
Dear all,

Is there any ways to refresh form from a subform? Here is my situation:

subform's field: No. amount
0 100
0 100
1 200
1 200
2 50
2 50
2 50

Form's field: total amount = 350 --> count per No.
(not 750 --> can't use flowfield)

So, I have one field and one subform. I hope that when I modify amount field in the subform, it will also automatically refresh the value of field in the form. So far, the amount value (in the form) can only be refreshed after the pointer moving out from subform.
Can someone help me? Thanks

Karel

Answers

  • DaveTDaveT Member Posts: 1,039
    Hi Karel,

    A simple solution is to show the total in the subform - just like the info panel on sales orders
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • Revolution1210Revolution1210 Member Posts: 161
    Hi Karl

    Unfortunately, the Sub Form (form, not control) has no concept of the header form which it is a sub form of, so you can't force an update of the main form after a certain event on the sub form.

    This leaves you with a few options:

    1. Forget about it and just be aware that the field on the header will only be updated when you click somewhere in the header to activate it.

    2. Intrinsically link the field to a function, so that the field on the header only gets updated after you run a certain function, Functions > Release on a Sales Order for example.

    3. And this is a fudge... ..set a timer running on your main form with CurrForm.UPDATE in the OnTimer() trigger. This is a bit of a sledgehammer to crack a nut, but does work if you absolutely had to have it. You may also get some flickering of your subform. Oh, and it would be fairly resource intensive way to fix a small issue.

    Good luck :D
    Ian

    www.NextEqualZero.com
    A technical eye on Dynamics NAV
  • sendohsendoh Member Posts: 207
    Sendoh
    be smart before being a clever.
  • karlkarl Member Posts: 22
    Hi all,

    Thanks for the reply and suggestion. Sendoh, could you tell me how to use XMLDom that has been suggested by Garak ? well, sorry to ask this simple question because I'm just a beginner in NAV programming :oops: I've been tried to import the code into my NAV4SP3 environment but find some syntax error.

    Thanks,

    Karel
  • SavatageSavatage Member Posts: 7,142
    if you're looking for a running type total.

    here's another way
    http://www.mibuso.com/forum/viewtopic.php?t=25056
  • sendohsendoh Member Posts: 207
    hi karl,

    what is the specific error?
    Sendoh
    be smart before being a clever.
  • karlkarl Member Posts: 22
    Savatage, thanks for your idea, it is nice.
    Sendoh, here is step to duplicate:
    1. Copy all the code into text file.
    2. In NAV, import the text file from object designer (I'm only change the form ID) and receive this error:

    There is a syntax error in the import on line 15 in position 11: Create(XmlDoc);.
    The AL Code is not indented as much as the first lin.


    Regards,

    Karel
  • sendohsendoh Member Posts: 207
    because it is not indented..try this one..copy the code to notepad and import to your DB.
    OBJECT Form 60000 main form
    {
      OBJECT-PROPERTIES
      {
        Date=06/12/08;
        Time=11:17:23 AM;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=5610;
        Height=4180;
        OnOpenForm=BEGIN
                     CREATE(XMLDoc);
                     CurrForm.SubForm.FORM.SetXMLDoc(XMLDoc);
                   END;
    
        OnCloseForm=BEGIN
                      CLEAR(XMLDoc);
                    END;
    
      }
      CONTROLS
      {
        { 1000000000;TextBox;330  ;440  ;2800 ;440  ;Editable=No;
                                                     SourceExpr=vTotal }
        { 1000000001;SubForm;330  ;990  ;3630 ;1760 ;Name=SubForm;
                                                     SubFormID=Form60001 }
      }
      CODE
      {
        VAR
          vTotal@1000000000 : Decimal;
          XMLDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40" WITHEVENTS;
    
        EVENT XMLDoc@1000000001::ondataavailable@198();
        BEGIN
        END;
    
        EVENT XMLDoc@1000000001::onreadystatechange@-609();
        BEGIN
          IF (XMLDoc.readyState = 4) THEN BEGIN
            vTotal := CurrForm.SubForm.FORM.GetText();
            CurrForm.UPDATE(FALSE);
    
          END;
        END;
    
        BEGIN
        END.
      }
    }
    
    OBJECT Form 60001 Sub form
    {
      OBJECT-PROPERTIES
      {
        Date=06/12/08;
        Time=11:18:17 AM;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=2640;
        Height=1320;
      }
      CONTROLS
      {
        { 1000000000;TextBox;110  ;110  ;2310 ;440  ;SourceExpr=vValue1;
                                                     OnAfterValidate=BEGIN
                                                                       SendMessage;
                                                                     END;
                                                                      }
        { 1000000001;TextBox;110  ;660  ;2310 ;440  ;SourceExpr=vValue2;
                                                     OnAfterValidate=BEGIN
                                                                       SendMessage;
                                                                     END;
                                                                      }
      }
      CODE
      {
        VAR
          vValue1@1000000000 : Decimal;
          vValue2@1000000001 : Decimal;
          XmlDoc@1000000002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40";
    
        PROCEDURE SetXMLDoc@1000000000(pXMLDoc@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40");
        BEGIN
          XmlDoc := pXMLDoc;
        END;
    
        PROCEDURE SendMessage@1000000002();
        BEGIN
          XmlDoc.loadXML('<root></root>');
        END;
    
        PROCEDURE GetText@1000000004() : Decimal;
        BEGIN
    
          EXIT(vValue1+vValue2);  //----------to be pass to main form-----------
        END;
    
        EVENT XmlDoc@1000000002::ondataavailable@198();
        BEGIN
        END;
    
        EVENT XmlDoc@1000000002::onreadystatechange@-609();
        BEGIN
        END;
    
        BEGIN
        END.
      }
    }
    



    hope will help..
    Sendoh
    be smart before being a clever.
  • karlkarl Member Posts: 22
    Wow, thanks Sendoh. It works \:D/

    Thanks for your help. CASE CLOSED.
  • sendohsendoh Member Posts: 207
    don't forget to mark it [SOLVE] :D
    Sendoh
    be smart before being a clever.
  • karlkarl Member Posts: 22
    Can anyone tell me how to close a topic ? :-k
    I can't find it in FAQ.


    Karel
  • Big_DBig_D Member Posts: 207
    Hi Sendoh

    That was brilliant - haven't got a clue that it works but it does!

    Well done that man :D!

    Cheers

    Big D
    Big D signing off!
  • garakgarak Member Posts: 3,263
    ho, that looks like my code ;-)
    Do you make it right, it works too!
Sign In or Register to comment.