473,785 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create Pivot Table using VBA (Access 2007)

34 New Member
I have produced an Excel (2007) worksheet, with which I want to create a Pivot Table. This would all be done from a module run on an Access 2007 database.

Please can anyone supply some simple code for this?

Many thanks for any help received.
Apr 21 '09
32 23396
NeoPa
32,578 Recognized Expert Moderator MVP
.SpecialCells(x lLastCell) is really useful in Excel worksheets, but there are circumstances where it's unreliable (When rows or columns have been deleted since the last save for instance).

A technique I use to get the last Row or Column of a particular column or row (NB. Only works when you know which column or row to look in) is to go to the last position and skip back.

EG. If I know that column A has a unique identifier in it (or PK), then I use :
Expand|Select|Wrap|Line Numbers
  1. Dim lngLastRow As Long
  2.  
  3. lngLastRow = Range("A65536").End(xlUp).Row
If I know Row 1 has the titles in it I may use (for the Column) :
Expand|Select|Wrap|Line Numbers
  1. Dim intLastCol As Integer
  2.  
  3. intLastCol = Range("IV1").End(xlToLeft).Column
These techniques are the VBA equivalents of using Ctrl-Up & Ctrl-Left from the extreme edges of the worksheet.
Apr 22 '09 #21
redman08
34 New Member
Re. xlPivotTableVer sion12 ...I've got a blank line.
Apr 22 '09 #22
NeoPa
32,578 Recognized Expert Moderator MVP
That makes sense. That is a value set up in Excel, and probably available only there.

You can get around this by defining a constant in your code.
Apr 22 '09 #23
FishVal
2,653 Recognized Expert Specialist
Sacramental question:
Do you have "Microsoft Excel xx.x Object Library" referenced?
Apr 22 '09 #24
redman08
34 New Member
Checked on Excel: xlPivotTableVer sion12 is set to 3, so have replaced xlPivotTableVer sion12 with a constant.

Still no go!

I don't have "Microsoft Excel xx.x Object Library" referenced.
Apr 22 '09 #25
FishVal
2,653 Recognized Expert Specialist
So, reference it or use numeric equivalent of excel constants.

Oh, sorry, I see you've already tried. Did you replace all constants?

P.S. Anyway, I strongly recommend you to reference excel library in Access project. It will add Excel constants to Access namespace and enable Intellisense to resolve excel object model.
Apr 22 '09 #26
NeoPa
32,578 Recognized Expert Moderator MVP
That's an Office 2007 constant I see.

I tested in Access 2003 with a database with an Excel reference and saw nothing. When I changed it to xlPivotTableVer sion10 it worked fine for me, so a reference to Excel should make that constant available to you, as Fish so rightly says.
Apr 22 '09 #27
redman08
34 New Member
I've added Microsoft Excel 12.0 Object Library and Microsoft Office 12.0 Object Library into my References....a nd am still getting '448' errors on line 2.

The code currently looks like this:
Expand|Select|Wrap|Line Numbers
  1. With AppExcel.ActiveWorkbook.PivotCaches
  2.     With .Add(SourceType:=xlDatabase, SourceData:=Datasheet.Range("A1:H" & LastRowNumber), Version:=3)
  3.         Set PTable = .CreatePivotTable(TableDestination:=CurrentSheet.Range("A6"), TableName:="AnalysisPivot", DefaultVersion:=3)
  4.     End With
  5. End With
There's not much to look at on that line. The SourceData is being referenced ok (have tested in debug for that); the Version number is ok. The only thing is "xlDatabase " - where is that picked-up from?
Apr 23 '09 #28
FishVal
2,653 Recognized Expert Specialist
I'd like to draw your attention back to post #14 and #16.
Could you check in object browser (button F2 in VBA IDE) what method PivotCaches class has "Add" or "Create" and what are arguments for the existing method?
Apr 23 '09 #29
redman08
34 New Member
Eureka!

It is Create, not Add, and the remaining parameters are as they are now.

Has run...now only the remaining bits...formatti ng...usage., etc.


Many thanks to all contributors.
Apr 23 '09 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5845
by: Rob | last post by:
I'm just getting around to using pivot tables and charts. I find the Pivot table interface to be INCREDIBLY frustrating. When I view a table in Design view, then choose Pivot table view, I get the PivotTable Field list, from which I can choose to add fields to the view. 1. How do you get RID of a field once you put it in? I can not right click on anywhere in the view and have ANY of the submenu options be availble. From the PivotTable...
4
11695
by: Ajay | last post by:
Hello all, I used to display reports in Excel earlier on my website. Now the client has requested that he would like see reports in Pivot table on the web . The backend is Sql2000. Can you please help in determining hoe we can create a pivot table and display records in it using C#? Thanks Ajay
1
3281
by: peter | last post by:
Dear all, I have an existing query called 'A', but I want it to view in Pivot Table. What I do is : - Double click the query and choose Pivot Table view. - I make some changes by adding some fields to the pivot table. - Next, I want to save these setting as a new query. (Because I know that multiple templates may be needed to keep track as user has change the
9
6798
by: PeteCresswell | last post by:
I've got something called "Reference Rates". The idea is that on a given day, we have various rates of return for various entities. e.g. Libor 3-month return, Libor 6-month return, US Treasury Bonds, the Prime rate, and so-forth. We associate a security with one of those rates. There are a set of rates for each calendar day, and the rates for that
2
13530
by: LittlePhil via AccessMonster.com | last post by:
Someone please help before i start to cry. I'm trying to export from Access to Excel, then create a new excel sheet with a pivot table to display the data held in columns A:P. I get the error message "Run Time error 91: Object variable or with block variable not set" on the "CREATE PIVOT" line below and can't find a way round. Please someone. Help! Option Compare Database
18
4529
by: smckibbe01 | last post by:
I have Pivot Table query in MS Access that I would like to run in SQL Server 2005. Can anyone help me to convert the syntax over to SQL Server. The following is the query in MS Access: TRANSFORM SUM(ps.psScheduled) SELECT pi.piMaxTurns, pi.piAMP, pi.piTons, '', '', ps.psPipe
0
1059
by: Sport Girl | last post by:
Hello everybody, please can anybody help me: How to make in a Pivot Table designed in Access 2007 a link from each field in the Pivot table to the corresponding row in the table in the database. This tip we can use it in Excel. Does anybody ahs an idea?
1
2204
by: mld01s | last post by:
I really need help!!! I dont know if its possible to share pivot tables, or see pivot tables in other machines that the one where the tables were created. This is what happens: I created a database to track different daily results. In a form in that database I added a pivot table, this table lets me see the results, sort them, and everthing a pivot table should let users do. Below the pivot table on the same form I have some fields for...
0
2138
by: Clare CAVS | last post by:
I have a table with a lookup column referring to another table . tblRooms has two fields, (Autonumber), and . The column I want to display is the RoomName column. If I have Bound Column = 1, and Column Count = 2, Column Widths 0cm;3cm I get the display I want. However, if I change the Bound Column to 2, this changes the values displayed – I now get column 1 values (RoomID) displaying, regardless of what I set for the Column Count and...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.