Filter subform

Get our Free Newletter

Don't you have the time to be online here at DUG every day? So how do you follow what is going on in the Dynamics industry and community?
If you subscribe to the DUG Newsletter then you can relax! We will make sure that you don't miss the big news!

Check out our
Newsletter Subscription Center
page a complete list of our different newsletters.

Solution (Verified) This post has 1 verified solution | 13 Replies | 1 Follower

82 Posts
995 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal
Luís Correia posted on 2011-9-21 12:21

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?

Solution (Verified) Verified Solution

108 Posts
3,217 Points
Joined: 2010-4-22
Last Online:
2014-8-28 17:35
Location: Germany
Solution (Verified) Thomas Martin replied on 2011-9-21 15:08
Verified by Luís Correia

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.

 

All Replies

4,945 Posts
126,434 Points
Joined: 2009-2-17
Last Online:
2014-10-25 5:54
Location: Hyderabad, India
DynamicsNAVMVP
Moderator
Mohana replied on 2011-9-21 12:27

Check SubFormLink propery in subform..

82 Posts
995 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal
Luís Correia replied on 2011-9-21 12:29

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...

4,945 Posts
126,434 Points
Joined: 2009-2-17
Last Online:
2014-10-25 5:54
Location: Hyderabad, India
DynamicsNAVMVP
Moderator
Mohana replied on 2011-9-21 12:36

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

82 Posts
995 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal
Luís Correia replied on 2011-9-21 14:45

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);

4,945 Posts
126,434 Points
Joined: 2009-2-17
Last Online:
2014-10-25 5:54
Location: Hyderabad, India
DynamicsNAVMVP
Moderator
Mohana replied on 2011-9-21 14:53

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);

Male
1,432 Posts
38,765 Points
Joined: 2007-3-2
Last Online:
2014-5-13 19:42
Location: Houston, TX, USA
DynamicsNAVMVP
Moderator
Matt Traxinger replied on 2011-9-21 15:04

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?

82 Posts
995 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal
Luís Correia replied on 2011-9-21 15:05

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

108 Posts
3,217 Points
Joined: 2010-4-22
Last Online:
2014-8-28 17:35
Location: Germany
Solution (Verified) Thomas Martin replied on 2011-9-21 15:08
Verified by Luís Correia

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.

 

4,945 Posts
126,434 Points
Joined: 2009-2-17
Last Online:
2014-10-25 5:54
Location: Hyderabad, India
DynamicsNAVMVP
Moderator
Mohana replied on 2011-9-21 15:09

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

82 Posts
995 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal
Luís Correia replied on 2011-9-21 15:24

Thomas Martin's solution worked. Thanks!!

4,945 Posts
126,434 Points
Joined: 2009-2-17
Last Online:
2014-10-25 5:54
Location: Hyderabad, India
DynamicsNAVMVP
Moderator
Mohana replied on 2011-9-22 6:52

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

is it filtering the subform?

82 Posts
995 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal
Luís Correia replied on 2011-9-22 9:10

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).

4,945 Posts
126,434 Points
Joined: 2009-2-17
Last Online:
2014-10-25 5:54
Location: Hyderabad, India
DynamicsNAVMVP
Moderator
Mohana replied on 2011-9-22 9:14

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

Yes

Page 1 of 1 (14 items) | Get this RSS feed | Bookmark and Share