Access to Mainform from Subform

Hi there, i have 2 questions: 1) How do i access datafields of the mainform from within a subform ? I want to get the “Nr.” field from an article which is active on the main form from the code in the subform. 2) I have a mainform “article” and a subform “article-lines”… When i go into the subform then the article number from the actual article should automatically be inserted in the “article-lines” subform like Navision does it with the invoice forms… i couldn’t find out how the procedure goes… Does anyone know ? :wink: Thanks so far. Kind regards, Marc

  1. How do i access datafields of the mainform from within a subform ? I want to get the “Nr.” field from an article which is active on the main form from the code in the subform<< You can’t… that’s something that Navision should need improving in next versions, as it’s illogical being unable of accesing the “parent” form where a subform is (it can be really helpfully having, for example, a CurrContext variable where knowing if running as stand-alone window or as subform and being able of accessing the parent properties from it when in a subform). >>2) I have a mainform “article” and a subform “article-lines”… When i go into the subform then the article number from the actual article should automatically be inserted in the “article-lines” subform like Navision does it with the invoice forms… i couldn’t find out how the procedure goes… Does anyone know ? ;-)<< Navision doesn’t really takes the article number from the actual article from the subform… it’s send to the subform by the main one using the SubFormLink property. On the main form, you should include a subform component for including the lines form. When doing that, on the subform component properties, modify the SubFormLink property so it links the data between your main form and the subform one. In your case the SubFormLink property should look (more or less) something like this: “subformtable_number_of_article_field”=FIELD(“mainformtable_Numberofarticle_field”) Regards :wink: – Alfonso Pertierra apertierra@teleline.es Spain

Hi Apertierra, well that’s something i already done, but the problem is, that the lines in the subform are emty and the Article Nr. which is actually on the mainform should be set in the line, so that at next run the form-link property could take effect… In other words: Subform: Take the article.Nr. and insert it in the line “artnr.” everytime the user enters something in the line… that would be a statement for the insert trigger in the table… but i don’t know how to access the “actual nr.”… :wink: Have a nice day :wink: Marc

Hi together, I solved my problem. Maybe somebody want’s to know: 1. Define a function in the subform with parameter 2. Use the on activate trigger in the Mainform and call the function in the subform with the field you want to have in the subform as parameter 3. transfer the parameter in a variable defined in the subform. Regards, Marc

  1. Most important point is that you create the Subform-link between article and article lines as Alfonso already had pointed out. This creates a filter on the articlelines table and you can easily find out the article with: MasterArticle := articlelines.Getfilter(“ArtNr.”); 2. It’s true that you cannot access fields from the parent-form. However you definitely CAN assess the fields of the parent table: Simply read the master record with a second statement: article.Get (Masterarticle); — Have a look at tables 36/37 which are an example of classical parent/child relationship. Marcus

You can modify the table, but you still have the problem of having in most cases to update the parent form… that it’s not as easy as it should be… (Example: having a normal field that must be calculated on parent after processing some info in the subform and it’s a field visible to the user on the main… he will see the old value after changing it from the subform…). Regards, – Alfonso Pertierra apertierra@teleline.es Spain

Hi Alfonso, Hi Fabian, thanks so far for your infos. My routines now work fine… It is a module for exporting article- data in an internet-shop i once programmed in VBasic and ASP (SqlS/Access DB). The routine belonging to the “article-lines” is the part which imports orders from the net and creates the customer also as the order… In that case it also maybe interesting to update the mainform which may be a little problematic as Alfonso wrote… How can that be solved ? I didn’t find a kind of form.refresh routine which just refreshes a form… Have you solved this ever ? Have a nice day, MarcS

As Alfonso already said, it’s not only difficult but impossible to update the mainform from the subform. The function you are looking for (refresh) is update (e.g. CurrForm.Update) but this function is useless as you don’t have any access from a subform to the parent form. Something like … CurrForm.Parent.Update; … unfortunately doesn’t exist. Probably the following would work: Put some code in the OnTimer trigger of the mainform to have values updated regularily. This might work but it could also be that the CurrForm.Update on the mainform takes away the focus from the subform. Second idea: instead for having a mainform/subform combination, only make one Subform where the tablebox only occupies the lower part of the screen while the upper part looks like a main form but simply contains common data (see Form 39 as example). This requires more efforts in programming but can be done. Marcus Marcus Fabian phone: +41 79 4397872 m.fabian@thenet.ch