Form with filtered records and subform

Hi all. I thought this was an easy one, but I was wrong… In the Sales Form, after selecting one line I push a button to open a particular form. This form will show several information regarding the line selected. It will filter just the records who have that client and have the product shown in that line. Well, not a problem, this is easy. Just opening a form with a rec filtered using settableview. Now comes the tricky question:[}:)] The form that opens contains two tables. As you all know, one form can only point to a particular table, not two, so I put a subform pointing to the second table that is also needed. The first table (the form table) is always correctly filtered. The problem is to tell the subform to filter also its records. I’ve already made a function to set 2 variables to the values to filter the second table, and called the function from the main form, BUT, I can’t make the final step, I can’t filter the subform. I’ve tried several ways, through settableview, put code in several triggers, but I was unlucky.[xx(] Can someone help me? Thanks

quote:


Originally posted by BFernandes
Hi all. The form that opens contains two tables. As you all know, one form can only point to a particular table, not two, so I put a subform pointing to the second table that is also needed. The first table (the form table) is always correctly filtered. The problem is to tell the subform to filter also its records. I’ve already made a function to set 2 variables to the values to filter the second table, and called the function from the main form, BUT, I can’t make the final step, I can’t filter the subform. I’ve tried several ways, through settableview, put code in several triggers, but I was unlucky.[xx(]


Maybe this is a silly question, but is there anything in SubFormLink property? Anna

Hi. No, I took it off and I’ll tell you why. If I made the link normally, connecting the client and the product number, the subform would be filtered to those values. This sounds fine, but there’s one little exception: If the table box in the main form doesn’t have any record after applying the filter, the link to the subform doesn’t work because the client and product number are null and every single record appears on the subform. Any ideas?

quote:


Originally posted by BFernandes
Hi. No, I took it off and I’ll tell you why. If I made the link normally, connecting the client and the product number, the subform would be filtered to those values. This sounds fine, but there’s one little exception: If the table box in the main form doesn’t have any record after applying the filter, the link to the subform doesn’t work because the client and product number are null and every single record appears on the subform. Any ideas?


I’d say that in such a case (which can be tested in the OnPush trigger of the launching button), the main form shouldn’t open at all. Once the offending situation is out of the way, you can use the SubFormLink as usual. Anna

What do you mean by that? Check previously if the filter will return 1 or more records and open the form, otherwise do what? Run another form similar to the original, but just with one table (the second one) ?

quote:


Originally posted by BFernandes
What do you mean by that? Check previously if the filter will return 1 or more records and open the form, otherwise do what? Run another form similar to the original, but just with one table (the second one) ?


In the OnPush trigger of the launching button, I guess, you settle filters on the table that will be showed by the main form you are going to launch. Well, once you have settled the filters, you might add some code like this: IF YourTable.FIND(‘-’) THEN FORM.RUN(…) ELSE MESSAGE(‘Sorry, there is nothing to show’); Maybe it is not very elegant, but it would spare you a lot of pain in … guess you know where. [;)] Anna

Hi, Anna. Well, my solution was this: I made another form, very similar to the original, that if there wasn’t any record to show in the main form, this second form would appear with just the second tablebox with some records. This is a simple approach, but the disavantage is that it requires an adicional form. Thanks.

quote:


Originally posted by BFernandes
Hi, Anna. Well, my solution was this: I made another form, very similar to the original, that if there wasn’t any record to show in the main form, this second form would appear with just the second tablebox with some records. This is a simple approach, but the disavantage is that it requires an adicional form. Thanks.


I’m not sure about what you mean with “some records”, but I’m glad you found a solution which seems to suite you. [:)] Anna

Hi. Yes, I found a solution that suites me using two forms. I made the second form to filter and show the records that belong in the subform of the “original” form. In my first approach, the subform couldn’t be linked if the tablebox in the mainform wouldn’t have any records, right? So, to avoid that, the second form filters the second tablebox independently of the mainform, because that form will only be launched if the mainform doesn’t have any records to show. It’s not the optimal solution, but it works [;)]