Filter subform

Hi there.

This may seem like a silly and beginner question, but I haven't found the answer anywhere.

I have a form, with a subform in it, and I need to filter a field on the subform (list), based on the value of another field in the main form (card).

For example, my current record in the main form has a field called "type", and its value is 'abc', I want to filter the subform's "type" field with the value 'abc'. Only the lines whose "type" value is 'abc' should appear on the subform.

How do I do it?


Luís Correia
  • Check SubFormLink propery in subform..


    -Mohana http://mohana-dynamicsnav.blogspot.in/

    Mohana | Blog | LinkedIn
  • In reply to Mohana:

    I did. But I haven't been able to filter the subform.

    In any case, i'd prefer to filter the subform via code, since I need to set another condition, in which the filter depends on the value of another field in the form...


    Luís Correia
  • In reply to Luís Correia:

    You need to try by adding filter code to subform records in Onvalidate trigger of main form field..


    -Mohana http://mohana-dynamicsnav.blogspot.in/

    Mohana | Blog | LinkedIn
  • In reply to Mohana:

    Still haven't been able to filter

    I wrote this code on the OnAfterGetRecord trigger of the main form. Is there something missing?

    (the form_diario_fusao is a form variable of the subform,)


    recDiarioFusao.RESET;
    recDiarioFusao.CALCFIELDS(DescMaterial);
    recDiarioFusao.SETRANGE(DescMaterial, "Cod. Material");
    IF recDiarioFusao.FINDFIRST THEN
    MESSAGE('%1', "Cod. Material");
    recDiarioFusao.CALCFIELDS(DescMaterial);
      MESSAGE('%1', recDiarioFusao.DescMaterial);
      form_diario_fusao.SETTABLEVIEW(recDiarioFusao);


    Luís Correia
  • In reply to Luís Correia:

    I think you need to create a function in Subform and call it from main form by passing the field value

    CurrForm.SalesLines.FORM.Filterlinerecords(mainrec.field);


    -Mohana http://mohana-dynamicsnav.blogspot.in/

    Mohana | Blog | LinkedIn
  • In reply to Mohana:

    Also, just think about where you put your code. OnAFTERGetRecord. As in you have already gotten the data. Would you filter the data after you've already gotten it from the database, or before?


    Matt Traxinger
  • In reply to Matt Traxinger:

    I read that somewhere, and it makes sense, but what would that function do?


    Luís Correia
  • In reply to Mohana:

    You need to reference directly to the Subform control and not just another instance of the form.

    Give the subform control a name in the properties. Let's say MySubForm.

    Then you can use:

    CurrForm.MySubForm.FORM.SETTABLEVIEW(recDiarioFusao);

    Or via function on the Subform as suggested.

     


    Thomas Martin
  • In reply to Thomas Martin:

    Function should filter the Line records based on the passed value..


    -Mohana http://mohana-dynamicsnav.blogspot.in/

    Mohana | Blog | LinkedIn
  • In reply to Mohana:

    Thomas Martin's solution worked. Thanks!!


    Luís Correia
  • In reply to Luís Correia:

    if you modify the value in main form type field from abc to xyz?

    is it filtering the subform?


    -Mohana http://mohana-dynamicsnav.blogspot.in/

    Mohana | Blog | LinkedIn
  • In reply to Mohana:

    Yes and no.

    No, because it's not an editable field.
    Yes, because it changes when I change the record (and the value is different).


    Luís Correia
  • In reply to Luís Correia:

    Luís Correia
    because it's not an editable field.

    Yes


    -Mohana http://mohana-dynamicsnav.blogspot.in/

    Mohana | Blog | LinkedIn
Related