How To Add Filter A Pie Pivot Chart When it is loaded In Code

  • Thread starter nouveauricheinvestments
  • Start date
N

nouveauricheinvestments

I'm trying to apply a filter to my subform, which is a pivot chart,
using the following code in the form_load event procedure.

DoCmd.ApplyFilter "Employee = " & Form_Dashboard.ThisUser

My parent form which contains the pivot chart is bound to the query
which the underlying subform is based off of.

The error message I am getting is the following:

The Microsoft Office Access database engine could not find the object
'Employee=Robin Tanner'. Make sure the object exists and that you
spell its name and the path name correctly.

I have a field in the record source query called 'Employee' as well as
several records in this field which list Robin Tanner. What should I
be doing differently?
 
D

Douglas J. Steele

Since Employee is (presumably) a Text field, you need quotes around the
value:

DoCmd.ApplyFilter "Employee = """ & Form_Dashboard.ThisUser & """"

That's three double-quotes before, and four double quotes after. (Ordinarily
I would use single quotes, but since names can contain apostrophes, that
could lead to problems in this case)
 
N

nouveauricheinvestments

Since Employee is (presumably) a Text field, you need quotes around the
value:

DoCmd.ApplyFilter "Employee = """ & Form_Dashboard.ThisUser & """"

That's three double-quotes before, and four double quotes after. (Ordinarily
I would use single quotes, but since names can contain apostrophes, that
could lead to problems in this case)

When I try to open the form, it gives me the following error after
having changed my Form_Load event to have the code you have specified:

The Microsoft Office Access database engine could not find the object
'Employee="Robin Tanner"". Make sure the object exists and that you
spell its name and the path name correctly.

When I open the subform in design view, I can see however that the
filter under properties lists the following:

Employee='robin tanner'

What do you think?
 
D

Douglas J. Steele

Is there a field named Employee in the RecordSource of the form, or might it
actually be named something else?
 
N

nouveauricheinvestments

Is there a field named Employee in the RecordSource of the form, or might it
actually be named something else?

Yes there is - The record source for the form is a query with the
following fields:

DAT
Employee
Reason
 
D

Douglas J. Steele

Instead of ApplyFilter, try

Me.Filter = "Employee = """ & Form_Dashboard.ThisUser & """"
Me.FilterOn = True
 
N

nouveauricheinvestments

Instead of ApplyFilter, try

Me.Filter = "Employee = """ & Form_Dashboard.ThisUser & """"
Me.FilterOn = True

I think I tried that before and it didn't work but I will give it
another whirl...
 
N

nouveauricheinvestments

Instead of ApplyFilter, try

Me.Filter = "Employee = """ & Form_Dashboard.ThisUser & """"
Me.FilterOn = True

The following is what I have and I am getting an error that says
"Invalid Use Of Property" when I attempt to load the form:

Me.Filter "Employee = """ & Form_Dashboard.ThisUser & """"
Me.FilterOn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top