Link between Main and subform

Hi I have a Form and a Subform. This application is used to generate invoices. But it is different from the Navision one. In the sense the invoice number is generated only after selecting the JobNo.(and based on some conditions). And also a job can have more than one invoice number. So suppose if i have created an invoice for Job1 with invoice number as INV1, then i enter lines for this invoice. Now if i want to create a second invoice for the same Job1, when i select the Job1 and generate the invoice Number say INV2 and when i go to the subform i can see the lines created for the same Job1 of the previous invoice INV1. Which is not anticipated, i want the subform not to show any lines if exist for any job previously. Each time i select a jobno and generate an invoice number then the lines should be emty until i enter values The PK for the header table is JobNo. and InvoiceNo The Pk for the lines table is JobNo. and LineNo The link between main form and subform is JobNo. can this be achieved. Thanx Kumar

Hi Kumar, add InvoiceNo to the primary for the lines tables (JobNo., InvoiceNo, LineNo) and link the subform using both JobNo and InvoiceNo. You can define several conditions in the SubFormLink Property of the subform, which apply simultaneously (AND). Saludos Nils

Hi Nils i know it will work the way as u said, but according to the requirements i cannot have InvoiceNo as PK for the line table. Hope u understand the problem now. Thanx kumar

Well, I don’t really get the point why InvoiceNo is not posible as part of the primary key, but if this is not possible you will need to code the necessary filter on the subform. In the main form add in the respective triggers (OnNextrecord, OnNewRecord) a call to a function that is defined in the subform, passing the current record to the subform. On the subform, define a new function than uses the record from the mainform to set the respective filter. If you have a look at the Sales Form the commands in the Lines Button work this way. Saludos Nils

Hi Nils please would you be more clear with your point. I didnt get what you were referring to wrt the sales line buttonns. thanx Kumar

Hi Kumar, sorry for the delay, hope this one helps. Add a new function to the subform, e.g. SetFilter, with a variable SalesHeader (T36). Add the following code in that fuction. SETRANGE(InvoiceNo,SalesHeader.InvoiceNo); CurrForm.UPDATE; In the header form, add in the OnAfterGetRecord the following statement: CurrForm.SalesLines.FORM.SetFilter(Rec); Sales Line Buttons - use the same idea of passing the header record to the subform to perform certain calculations. Saludos Nils