How to Use VBA Reference Pivot Table on Access 2010 Subform

I’m getting a type miss match (error 13) on the indicated line show below.

Dim subFormPTbl As Form    ' the subform with pivot table
Dim PTbl As PivotTable     ' refers to pivot table
Dim PTblFld As PivotField  ' a column field in the pivot table
Set subFormPTbl = Me.SuformWithPivot.Form
Set PTbl = subFormPTbl.PivotTable  ' < === ERROR HAPPENS HERE
For Each PTblFld In PTbl.ColumnFields
   If PTblFld.Selected Then
   Debug.Print "Selected column field name is " & PTblFld.Name
   End If
Next

I have a main form with a subform. The subform refers to a form with a default view set to pivot table. All I need to do is to list the column fields that are selected by the user.
robtrueAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What library are you using to reference a PivotTable?

You must refer to a Subform through it's host (i.e. Parent) form, so:

Set subFormPTbl = YourParentForm.YourSubformCONTROL.Form.ThePivotTable
1
robtrueAuthor Commented:
What library are you using to reference a PivotTable?

Below is the list of References:
Visual Basic For Applications
Microsoft Access 14.0 Object Library
OLE Automation
Microsoft Office 14.0 Access database engine Object Library
Microsoft Office 14.0 Object Library
Microsoft Excel 14.0 Object Library

I also tried the following changes:
   
    Set subFormPTbl = Forms.MainForm.subformControl.Form
   
    Set PTbl = Forms.MainForm.subformControl.Form.PivotTable

Still get the same runtime error at the same location. I’m wondering if I’m missing the right reference.

P.S. I was at USC back in the 80s.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Is "subformControl" the actual name of the Subform Control on your parent form?

Do you get an error on this line: Set subFormPTbl = Forms.MainForm.subformControl.Form? If not, then you're referencing the Subform correctly, which would indicate you've got troubles with the PivotTable call. I'm not sure, since I don't use it.

I don't think you're missing the reference, otherwise you'd get a different error.

Go Gamecocks!!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

robtrueAuthor Commented:
There is no error in the line:
Set subFormPTbl = Forms.MainForm.subformControl.Form

The error is with the PivotTable.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Can you upload the database? If so, remove any sensitive information first.
0
robtrueAuthor Commented:
Pleas find attached an Access 2010 .accdb file which illustrates the problem.
Database1.accdb
0
robtrueAuthor Commented:
Well, I know the answer.  So, I’ll tell you the answer.  Simply put, Microsoft has dumped Pivot Table and Pivot Chart from Access.  You will have to do the grunt work and interface with either Excel for pivot tables or use Access Crosstab.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.