assign form filter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a subform in a main form. How do I assign different filters to the
subform by clicking on different command buttons on the main form. I tried
using the following but it did not work:

'Forms!Frm_main.Frm_sub.Filter = "((Main.Group = 'CNC'))"
'Forms!Frm_main.Frm_sub.FilterOn = True

Thanks
Wendy
 
Hi Wendy

Filter and FilterOn are properties of a Form object.

Forms!Frm_main.Frm_sub is a reference to the subform *control* on your main
form. This is not a form, but a container for a form. It has a property,
"Form", which is a regerence to the Form object that it contains.

So, what you need is:
Forms!Frm_main.Frm_sub.Form.Filter = "((Main.Group = 'CNC'))"
Forms!Frm_main.Frm_sub.Form.FilterOn = True

Since this code is in the class module of Frm_main, the control Frm_sub is
in the local scope, so you can use "Me" instead of "Forms!Frm_main". Also,
it's a good chance to use a With statement:
With Me.Frm_sub.Form
.Filter = "((Main.Group = 'CNC'))"
.FilterOn = True
End With
 
I made the change you suggested and It works great.
Many Thanks!

Graham Mandeno said:
Hi Wendy

Filter and FilterOn are properties of a Form object.

Forms!Frm_main.Frm_sub is a reference to the subform *control* on your main
form. This is not a form, but a container for a form. It has a property,
"Form", which is a regerence to the Form object that it contains.

So, what you need is:
Forms!Frm_main.Frm_sub.Form.Filter = "((Main.Group = 'CNC'))"
Forms!Frm_main.Frm_sub.Form.FilterOn = True

Since this code is in the class module of Frm_main, the control Frm_sub is
in the local scope, so you can use "Me" instead of "Forms!Frm_main". Also,
it's a good chance to use a With statement:
With Me.Frm_sub.Form
.Filter = "((Main.Group = 'CNC'))"
.FilterOn = True
End With

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Wendy said:
Hi,
I have a subform in a main form. How do I assign different filters to the
subform by clicking on different command buttons on the main form. I tried
using the following but it did not work:

'Forms!Frm_main.Frm_sub.Filter = "((Main.Group = 'CNC'))"
'Forms!Frm_main.Frm_sub.FilterOn = True

Thanks
Wendy
 
Back
Top