Applying filter by form programatically

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

Guest

Created a form with 3 subforms. Each of the subforms was created from one
form, so all forms look at the same recordset. I need to be able to
progamtically apply filters to each of the subforms contained in the main
form. I can do this with filter by form button, but am at a loss to figure
it out with a macro. The idea behind this approach is not to create multiple
subforms where the only difference between them are selection criteria, so
modifing the form layout does not involve changing 3 forms. Any help would
be appreciated!!! Example:

Shows all What I'm after
Records (achieved filter by form buttons)
++++++++++ ++++++++++++++++++++++++++++++

Main Form Main Form
All Animals Filtered by Birds
All Animals Filtered by Cats
All Animals Filtered by Dogs
 
In the Click property of the specific button, put code like:

Me.Filter = "Animal = 'Bird'"
Me.FilterOn = True

You'll also want some way of specifying Me.FilterOn = False when you want to
remove the filter.
 
I either didn't explain myself well, or I don't understand the reply. Let me
try to explain myself again

I have a main form, let's call it M1. I created three subforms on it, let's
call them Sub1, Sub2, and Sub3. Sub1, 2 and three all have the same form
(Let's call it AllRec) specifed in the source object field.

Now, when M1 is opened, it shows all records (let's say all animals) in each
of the subforms. I can filter by form to have subform1 only show birds,
subform2 only show cats, and subform3 only show dogs.

This is what I'm attemping to do programatically.

As for the advice below, the click property is only available in "AllREC"
form, so I can't do this.

Also, the subforms only have two events (on enter, on exit), which will not
accomplish the filtering when the main form opens.

As far as I can tell, there is no event which is tied to the subforms at
main form open time.

Any ideas???

The only alternative I have tried, which works with partital success is to
create three fields on the M1, with Bird, Cat, and Dog as values for the
fields, and then link them to the subforms. However, I get a message "The
linksmaster fields property setting has produced this error - A problem
occurred while xx.db was communicating with OLE server or ActiveX control".
The error message is received when I scroll to the last record on each of the
subforms, and only occurs once after form open for each form.

Any help would be greatly appreciated.

Thanks..
 
On M1, you can set the filters to the forms in Sub1, Sub2 and Sub3 as:

Me.Sub1.Form.Filter = "Animal = 'Bird'"
Me.Sub1.Form.FilterOn = True
Me.Sub2.Form.Filter = "Animal = 'Cat'"
Me.Sub2.Form.FilterOn = True
Me.Sub3.Form.Filter = "Animal = 'Dog'"
Me.Sub3.Form.FilterOn = True
 
First of all, thanks Doug for the quick replys and sticking with this issue.
You guys that reply to the newsgroups are GREAT!

Unfortunately, this did not work. I put in the on current event of form M1
and received a message similar to the one stated in my prev post. This one
states:
++++
The expression on current you entered as the event property setting produced
the following error: A problem occurred while Blue Rock Customer Database
was communicating with the OLE server or ActiveX control

The expression may not result in the name of a macro, the name of a
user-defined function or [event procedure]

There may have been an error evaluating the function, event, or macro
+++++++++

Very similar to the message below, except this message does not have a help
button, (which incidentally takes me to the apply filter help screen)


BTW - I noticed in several posts objects referred to starting with ME. What
exactly is ME? Where do I find documentation on these types of fields???

P.S - I tried this approach prior to your post, but was using the fully
qualified form name (not using me). When I went that route, the filter
options were not availible in the expression builder.

Thanks again
 
Nothing comes to mind. Why are you putting it in the Current event? That
fires with every row: are you trying to change the filter depending on which
row you've selected in M1?



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



MSROOKIE said:
First of all, thanks Doug for the quick replys and sticking with this
issue.
You guys that reply to the newsgroups are GREAT!

Unfortunately, this did not work. I put in the on current event of form
M1
and received a message similar to the one stated in my prev post. This
one
states:
++++
The expression on current you entered as the event property setting
produced
the following error: A problem occurred while Blue Rock Customer Database
was communicating with the OLE server or ActiveX control

The expression may not result in the name of a macro, the name of a
user-defined function or [event procedure]

There may have been an error evaluating the function, event, or macro
+++++++++

Very similar to the message below, except this message does not have a
help
button, (which incidentally takes me to the apply filter help screen)


BTW - I noticed in several posts objects referred to starting with ME.
What
exactly is ME? Where do I find documentation on these types of fields???

P.S - I tried this approach prior to your post, but was using the fully
qualified form name (not using me). When I went that route, the filter
options were not availible in the expression builder.

Thanks again

Douglas J. Steele said:
On M1, you can set the filters to the forms in Sub1, Sub2 and Sub3 as:

Me.Sub1.Form.Filter = "Animal = 'Bird'"
Me.Sub1.Form.FilterOn = True
Me.Sub2.Form.Filter = "Animal = 'Cat'"
Me.Sub2.Form.FilterOn = True
Me.Sub3.Form.Filter = "Animal = 'Dog'"
Me.Sub3.Form.FilterOn = True
 
If someone has an answer to the issue below I would appreciate it for FYI,
however in the interest of closing the loop on this post, I have abandoned
this route, and went with using subforms and manually typing in (access will
not do it via a the ... button as per a KB article) the parent and child
filelds.

Thanks Doug for your time.

Douglas J. Steele said:
Nothing comes to mind. Why are you putting it in the Current event? That
fires with every row: are you trying to change the filter depending on which
row you've selected in M1?



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



MSROOKIE said:
First of all, thanks Doug for the quick replys and sticking with this
issue.
You guys that reply to the newsgroups are GREAT!

Unfortunately, this did not work. I put in the on current event of form
M1
and received a message similar to the one stated in my prev post. This
one
states:
++++
The expression on current you entered as the event property setting
produced
the following error: A problem occurred while Blue Rock Customer Database
was communicating with the OLE server or ActiveX control

The expression may not result in the name of a macro, the name of a
user-defined function or [event procedure]

There may have been an error evaluating the function, event, or macro
+++++++++

Very similar to the message below, except this message does not have a
help
button, (which incidentally takes me to the apply filter help screen)


BTW - I noticed in several posts objects referred to starting with ME.
What
exactly is ME? Where do I find documentation on these types of fields???

P.S - I tried this approach prior to your post, but was using the fully
qualified form name (not using me). When I went that route, the filter
options were not availible in the expression builder.

Thanks again

Douglas J. Steele said:
On M1, you can set the filters to the forms in Sub1, Sub2 and Sub3 as:

Me.Sub1.Form.Filter = "Animal = 'Bird'"
Me.Sub1.Form.FilterOn = True
Me.Sub2.Form.Filter = "Animal = 'Cat'"
Me.Sub2.Form.FilterOn = True
Me.Sub3.Form.Filter = "Animal = 'Dog'"
Me.Sub3.Form.FilterOn = True

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I either didn't explain myself well, or I don't understand the reply.
Let
me
try to explain myself again

I have a main form, let's call it M1. I created three subforms on it,
let's
call them Sub1, Sub2, and Sub3. Sub1, 2 and three all have the same
form
(Let's call it AllRec) specifed in the source object field.

Now, when M1 is opened, it shows all records (let's say all animals) in
each
of the subforms. I can filter by form to have subform1 only show
birds,
subform2 only show cats, and subform3 only show dogs.

This is what I'm attemping to do programatically.

As for the advice below, the click property is only available in
"AllREC"
form, so I can't do this.

Also, the subforms only have two events (on enter, on exit), which will
not
accomplish the filtering when the main form opens.

As far as I can tell, there is no event which is tied to the subforms
at
main form open time.

Any ideas???

The only alternative I have tried, which works with partital success is
to
create three fields on the M1, with Bird, Cat, and Dog as values for
the
fields, and then link them to the subforms. However, I get a message
"The
linksmaster fields property setting has produced this error - A problem
occurred while xx.db was communicating with OLE server or ActiveX
control".
The error message is received when I scroll to the last record on each
of
the
subforms, and only occurs once after form open for each form.

Any help would be greatly appreciated.

Thanks..

:

In the Click property of the specific button, put code like:

Me.Filter = "Animal = 'Bird'"
Me.FilterOn = True

You'll also want some way of specifying Me.FilterOn = False when you
want
to
remove the filter.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Created a form with 3 subforms. Each of the subforms was created
from
one
form, so all forms look at the same recordset. I need to be able to
progamtically apply filters to each of the subforms contained in the
main
form. I can do this with filter by form button, but am at a loss to
figure
it out with a macro. The idea behind this approach is not to create
multiple
subforms where the only difference between them are selection
criteria,
so
modifing the form layout does not involve changing 3 forms. Any
help
would
be appreciated!!! Example:

Shows all What I'm after
Records (achieved filter by form buttons)
++++++++++ ++++++++++++++++++++++++++++++

Main Form Main Form
All Animals Filtered by Birds
All Animals Filtered by Cats
All Animals Filtered by Dogs
 
Back
Top