Advertisement

03.18.2008 at 08:31AM PDT, ID: 23250553
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.8

Exporting Access query to Excel Pivot Table

Asked by gfranco in Access Coding/Macros, Microsoft Access Database

Tags: , ,

I have a query that need to be exported on Pivot Table for Analysis proposes.
The required pivot wanted is called "finalpivot.jpg"
I just got an error, "see runtime-jpg"
the code below only print me out the Base Data sheet and does not provide any row for a PartnerPiivot sheet.
This module is called "modPivotTable"

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
Public Sub PivotTableExportData()
Dim xlapp As Excel.Application
Dim xlwb As Excel.Workbook
Dim xlws As Excel.Worksheet
Dim xlrng As Excel.Range
Dim xlPivot As Excel.PivotTable
Dim adors As ADODB.Recordset
Dim adofld As ADODB.Field
Dim x, y, z As Integer
 
Set xlapp = New Excel.Application
xlapp.Visible = True
Set xlwb = xlapp.Workbooks.Add
Set xlws = xlwb.ActiveSheet
xlws.Name = "BaseData"
 
Set adors = New ADODB.Recordset
adors.Open "qryTotalByPartner", CurrentProject.Connection, adOpenStatic, adLockReadOnly
 
 
 
x = 1
For Each adofld In adors.Fields
  xlws.Cells(1, x).Value = adofld.Name
  x = x + 1
Next adofld
 
Set xlrng = xlws.Cells(2, 1)
xlrng.CopyFromRecordset adors
y = adors.RecordCount + 1
adors.Close
 
Set xlws = xlwb.Worksheets.Add
xlws.Name = "PartnerPivot"
Set xlrng = xlws.Range("A3")
 
 
xlws.PivotTableWizard Excel.xlDatabase, "BaseData!R1C1:R" & y & "C" & x - 1, _
  xlrng, "SalesPivotTable", True, True, True, True
  
Set xlPivot = xlws.PivotTables("PartnerPivotTable")
xlPivot.AddFields "Customer", "Created"
With xlPivot.PivotFields("TotalCost")
    .Orientation = Excel.xlDataField
    .NumberFormat = "$#,##0.00"
End With
 
Set xlPivot = Nothing
Set xlrng = Nothing
Set xlws = Nothing
Set xlwb = Nothing
Set xlapp = Nothing
Set adofld = Nothing
Set adors = Nothing
End Sub
 
Public Sub PivotTableChartExportData()
Dim xlapp As Excel.Application
Dim xlwb As Excel.Workbook
Dim xlws As Excel.Worksheet
Dim xlrng As Excel.Range
Dim xlPivot As Excel.PivotTable
Dim adors As ADODB.Recordset
Dim adofld As ADODB.Field
Dim x, y, z As Integer
 
Set xlapp = New Excel.Application
xlapp.Visible = True
Set xlwb = xlapp.Workbooks.Add
Set xlws = xlwb.ActiveSheet
xlws.Name = "BaseData"
 
Set adors = New ADODB.Recordset
adors.Open "qryTotalByPartner", CurrentProject.Connection, adOpenStatic, adLockReadOnly
 
 
 
x = 1
For Each adofld In adors.Fields
  xlws.Cells(1, x).Value = adofld.Name
  x = x + 1
Next adofld
 
Set xlrng = xlws.Cells(2, 1)
xlrng.CopyFromRecordset adors
y = adors.RecordCount + 1
adors.Close
 
Set xlws = xlwb.Worksheets.Add
xlws.Name = "SalesPivot"
Set xlrng = xlws.Range("A3")
 
 
xlws.PivotTableWizard Excel.xlDatabase, "BaseData!R1C1:R" & y & "C" & x - 1, _
  xlrng, "PartnerPivotTable", True, True, True, True
  
Set xlPivot = xlws.PivotTables("PartnerPivotTable")
xlPivot.AddFields "Customer", "Created"
'xlPivot.AddFields "LineofBusiness2", "ProductCategory"
With xlPivot.PivotFields("TotalCost")
    .Orientation = Excel.xlDataField
    .NumberFormat = "$#,##0.00"
End With
 
xlwb.Charts.Add
ActiveChart.SetSourceData xlrng
ActiveChart.Location Where:=Excel.xlLocationAsNewSheet
 
 
Set xlPivot = Nothing
Set xlrng = Nothing
Set xlws = Nothing
Set xlwb = Nothing
Set xlapp = Nothing
Set adofld = Nothing
Set adors = Nothing
End Sub
Attachments:
 
Base Data
Base Data
 
 
Final Pivot
Final Pivot
 
 
Run time error
Run time error
 
 
Partner pivot
Partner pivot
 
 
Debug mode
Debug mode
 
[+][-]03.18.2008 at 09:15AM PDT, ID: 21152638

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.18.2008 at 09:49AM PDT, ID: 21153075

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.18.2008 at 09:58AM PDT, ID: 21153171

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 11:37AM PDT, ID: 21164378

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 02:13PM PDT, ID: 21165972

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 07:07AM PDT, ID: 21171587

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 07:51AM PDT, ID: 21172094

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 07:57AM PDT, ID: 21172142

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 08:03AM PDT, ID: 21172214

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 08:34AM PDT, ID: 21172575

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 11:11AM PDT, ID: 21361153

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 07:38AM PDT, ID: 21377546

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 08:25AM PDT, ID: 21378177

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Coding/Macros, Microsoft Access Database
Tags: Microsoft, Access, 2003
Sign Up Now!
Solution Provided By: boag2000
Participating Experts: 1
Solution Grade: C
 
 
[+][-]04.17.2008 at 08:45AM PDT, ID: 21378397

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 10:13AM PDT, ID: 21379264

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 10:31AM PDT, ID: 21379396

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 11:41AM PDT, ID: 21380046

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628