Form and Subform question

Moin: Anybody out there who can give me a hint for this task: There are two tables CommentCode MyCommentLine Commentcode has the following fields: Comment Code CODE10 MyCommentLine has the following fields: Field No. Field Name Data Type Option String 1 Comment Type Option Before, After 2 Comment Code CODE20 3 Line No. Integer 4 Comment Text Text100 PK is Comment Type,Comment Code,Line No. MyCommentLine also has a procedure: SetUpNewLine SalutationDefaultLine.SETRANGE ( “Comment Type”, “Comment Type” ); SalutationDefaultLine.SETRANGE ( “Salutation Code”, “Salutation Code” ); Now I created a form where I can create and edit these comment Lines. It looks like this: Comment Code xxxxxxxxxxxxxxx ±-----------------------+ | Subform Comment Before | ±-----------------------+ ±-----------------------+ | Subform Comment After | ±-----------------------+ It contains the following trigger: OnNewRecord(BelowxRec : Boolean) SetUpNewLine; Both subforms display the field Comment Text of the Table MyCommentLine only. Subform Comment Before has the following properties of interest: SubFormID Subf. Comment Lines SubFormView SORTING(Comment Type,Comment Code,Line No.) WHERE(Comment Type=CONST(Before)) SubFormLink Comment Type=CONST(Before),Comment Code=FIELD(Comment Code) Subform Comment After has the following properties of interest: SubFormID Subf. Comment Lines SubFormView SORTING(Comment Type,Comment Code,Line No.) WHERE(Comment Type=CONST(Before)) SubFormLink Comment Type=CONST(Before),Comment Code=FIELD(Comment Code) All you see here is a variation of the Form 67 (Sales Comment Sheet) and the table 97 (Comment Line). (BTW: where does the incrementation of “Line No.” takes place?) The form works as it should when it´s only displaying the content of the table MyCommentLine in both subforms. Trouble starts, when I want to add lines in subform “Comment After” because the Comment Type in the new line remains at “Before”. Would be nice to get a hint that points me on the right track. Regards Alarich

quote:


Trouble starts, when I want to add lines in subform “Comment After” because the Comment Type in the new line remains at “Before”.


What kind of troble? Any ERROR-Messages? What about the Property “AutoSplitKey” in those CommandLine-Subforms? If it’s set to “Yes”, the Insert of records could fail if some wrong filters or sortings are set … [?][?][?] Regards, Jörg

Jörg: Thank you for yor input. The problem is, that “Comment Type” should be set to “After” when a new record is to be inserted in the subform “Comment After”. Currently “Comment Type” is still “Before” because it´s the first option. This results either in a key violation because it is highly probable that the combination Comment Type,Comment Code,Line No. already exist. If not, then the intended becomes a “Comment Before” and this doesn´t reflect my intentions :o) Regards Alarich

Maybe you could try this: Put in each Subform, Trigger OnNewRecord, this code

Subform Before - OnNewRecord
"Comment Type" := "Comment Type"::Before;
Subform After - OnNewRecord
"Comment Type" := "Comment Type"::After;

The Subfforms should be linked to the Mainform just by “Comment Code” - not “Comment Type”! The Filter on “Comment Type” should just be set by SubFormView. I suppose, you won’t need your function “SetUpNewLine” then. If the AutosplitKey-Property of each Subform is set to “Yes” it should work … [:p] Regards, Jörg

quote:


Subform Before - OnNewRecord “Comment Type” := “Comment Type”::Before; Subform After - OnNewRecord “Comment Type” := “Comment Type”::After;


This means, that there are two different Subforms! [B)]

Jörg: It works fine with two different Subforms. I was just targeting to avoid producing redundant code, because the two forms just differ in one parameter. Thought, it might be possible to pass a parameter when using a subform but obviously it´s not. Sometimes it´s hard coding in NAVISION being accustomed to “real” development systems :o) Regards Alarich

Alarich, You can use the same subform: On the subform, define a global variable to indicate ‘before’ or ‘after’, define a function that takes the argument and sets the global variable accordingly. On the mainform, give the subforms different names, e.g. sub1 and sub2. In the activate trigger of the mainform pass the correct values to the subforms: CurrForm.sub1.setvariable(‘Before’); CurrForm.sub2.setvariable(‘After’); Hope this helps