SubForm Recordsource & Filter

  • Thread starter Thread starter CJ
  • Start date Start date
C

CJ

Hi all I am using Access 2003.

Since filter by form does not work for subforms, I am trying to create a
filter on the fly.

I have a subform (fsubExplorationLocation) that has the recordsource of
tblExplorationLocation. I have created a parameter query
(qfrmExplorationLocation) that I only want to apply if the user clicks on a
"Location Filter" button.

So, when a user clicks the button on the main form, the recordsource of the
subform changes, the parameter is run and the filter applied (I hope). At
the moment I am receiving the following error message when I click on the
button: "Object Doesn't Support This Property or Method".

Could somebody please help me out with this problem??!!??

My code for the On Click Event of my button is as follows:

Me!fsubExplorationLocation.RecordSource = "qfrmExplorationLocation"
DoCmd.Requery Me!fsubExplorationLocation

Thanks in Advance.
 
When referring to a subform, you first have to refer to a control on the
main form called a subform control, then to the form used as a subform. The
name of this subform control may or may not be the same as the name of the
form used as the subform.

Example:
Me!fsubExplorationLocation.Form.RecordSource = "qfrmExplorationLocation"

Replace fsubExplorationLocation with the name of the subform control if it
is different than the name of the form used as the subform. The subform
control is where you set the Master/Child links.
 
Hi Wayne:

I have the correct reference names and I have corrected my code as you
showed in the example. The filter works sort of. What happens now is the
parameters all come up but after I say OK for the last one, I receive the
error message "An expression you entered is the wrong data type for one of
the arguments". These are all text fields and the query runs fine when you
just run the query.

The first record that is displayed does have the filter applied for the
subform, but I still have 100 records listed for the main form, I was
expecting that only the main form records that met the filter criteria would
be displayed. Also, there is no indication that a filter has been applied
anywhere.

Thanks for your help.
 
In the example you gave for what you're trying to do, the only thing that
should have been affected would have been the subform. You didn't do
anything to change what the main form displays. You could do the same thing
for the main form's Record Source if you desire. There are some bugs when
applying filters to a form/subform setup, but I believe that resetting the
Record Source should work around these problems. For information on the
problems, see this link.

http://www.allenbrowne.com/bug-02.html

You say all of the fields are text fields, but what type of data is actually
in them? Could Access be trying to help by providing a data type conversion
when you don't really want one?

As far as an indication that a filter has been applied, one hasn't been.
You've actually changed the Record Source, not set a filter in the form to
let the form do its own filtering.
 
Thanks for your insight Wayne.

We have actually figured out a workaround that does involve changing the
recordsource of the main form but I will look at the link to see what other
options we have.

Thanks!
 
Back
Top