Update subform record from form

rockyczrockycz Member Posts: 4
I have a form (table 1) with subform (table 2), after I get record for form (from table 1), i need to modify some rows in record for subform (modify table 2) and then show them in subform,

When i try to modify table 2 in AfterGetRecord in form, it ends up with error message - "You can not modify database by this activation signal" (I dont know exactly how it is in english, this is my translation of czech error message).

Is any way to modify table in subform when changing record in form ?

Thank you,

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    It is not very navision like to do it this way. Usualy the data changes after user input or upon a command. Not by just browsing trough a form. :?

    Have you tried the onaftergetcurrrecord trigger?
  • rockyczrockycz Member Posts: 4
    onaftergetcurrrecord makes the same error message, i need this because i need recalculate secondary keys for viewed records in subform, and i dont want recalculate all of them (tenthousands of records)
  • krikikriki Member, Moderator Posts: 9,118
    rockycz wrote:
    onaftergetcurrrecord makes the same error message, i need this because i need recalculate secondary keys for viewed records in subform, and i dont want recalculate all of them (tenthousands of records)
    What do you mean with
    recalculate secondary keys for viewed records
    If you mean you have to calculate some fields, before showing the values, it is not necessary to write them in the DB for viewing.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • rockyczrockycz Member Posts: 4
    I mean - after choosing record in form, I need to modify some values (secondary keys) in table, that are shown in subform (i need sort this subform by this values).

    Updating all values before form is opened is not good idea, that could take too much time, so i need to recalculate only values that are needed after record in form is selected (form = header, subform = rows).

    And i wonder if it is possible or not.

    Thanks.
  • krikikriki Member, Moderator Posts: 9,118
    You subform needs to work on a temptable.
    See Form 498 for what to put in the "OnFindRecord","OnNextRecord"-triggers.
    In the subform, you need to put a function that will be called from the main form. This function fills up the temptable and you can give the order you like.

    In the main form, you have to give your subform a name.
    In the "OnAfterGetCurrentRecord"-trigger of main form, you can call the function in the subform (something like "CurrForm.MySubForm.FORM.TheFunction")

    The only problem with a temptable in a form, is if the user changes the records. In this case you have to write some code to apply the changes to the real table.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    Hello rockycz,

    As you can see, it is not so easy. Yes, you need to do that in another way. For now, I mean that krikis' method is best. May be that you will find another way. For example you can add code into OnTimer and call this update functions from there if the Header record was changed (to prevent recalculations when user did not select another record...). It means, that lines will be updated for example 1 second (you can call it after 0,5 sec etc.) after you selected the record, but may be that it is enough for the user.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.