473,761 Members | 8,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create Excel Pivot Table from Access module

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
Option Explicit

Public Sub ftnMonitoring()

Dim varFileName As String
Dim varCurrentFile As Object
Dim varExcelApplica tion

varFilename = "C:\MyFile. xls"

'EXPORT DATA
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel9, "MyQuery",
varFileName, True

'OPEN EXCEL HIDDEN
Set varExcelApplica tion = CreateObject("E xcel.Applicatio n")
varExcelApplica tion.Visible = False

'OPEN DOCUMENT
Call Shell("EXCEL """ & varFileName, vbMinimizedFocu s)
Set varCurrentFile = GetObject(varFi leName & ".xls")

'RENAME SHEET
varCurrentFile. ActiveSheet.Nam e = "MyData"

'ADD NEW SHEET
varCurrentFile. Sheets.Add

'RENAME SHEET
varCurrentFile. ActiveSheet.Nam e = "PivotSheet "

'CREATE PIVOT
varExcelApplica tion.ActiveWork book.PivotCache s.Add(SourceTyp e:=1, SourceData:
="'MyData'!A:P" ).CreatePivotTa ble TableDestinatio n:="'PivotSheet '!R3C1",
TableName:="Why DontYouWork", DefaultVersion: =10

'SAVE AND CLOSE
varCurrentFile. Save
varCurrentFile. Application.Qui t

End Sub

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200702/1

Feb 24 '07 #1
2 13527
Ok so instead of crying i took a break; I've created some template files
which i copy and paste, then transfer data into; these have pivot tables all
set up and ready to go all i need to do now is convert;

ActiveSheet.Piv otTables("Pivot Table2").PivotC ache.Refresh

into access vba, so for my previous example this would be;

varCurrentFile. ActiveSheet.Piv otTables("WhyDo ntYouWork").Piv otCache.Refresh

The problem seems to lie in that i cannot define a pivotcache; any ideas
anyone?

Thanks very much for reading!

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200702/1

Feb 25 '07 #2
:-/

I don't get it - i tried this again today and it now works?! i got an error
message up to yesterday saying i had to define a pivotcache in my access
module....

oh well - thanks for reading!

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200702/1

Feb 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11932
by: John | last post by:
Is there a way to code the button that's available in the query window--microsoft excel icon that exports to excel. I know transferspreadsheet will do this---but I want the query, which is in a pivot table view, to be exported as a pivot, not just a data list. Does this code exist? Is it transferspreadsheet but with a twist?
0
1890
by: Alexander Mandl | last post by:
Hello I have a pivot table in an Access form and open the pivot Table (Excel OLE Object) from within Access. In the Excel Table is a macro (signed) (in teh open event) running when opening the excel object from within Access. Since my customer have installed O2K SP3 - the Makro does not run any longer. The curiosity is: If you open the Excel Object from within Access and then store it to a local file - then reopen this file - the same...
1
3887
by: Jerome Ranch | last post by:
I consider myself an Excel PT wizard of sorts, but now I have a situation with so much infromationthat I need to categorize and summarize, that I will use access to manage it. Interestingly, though, the pivot tables in excel 2003 do not resemble the pivot tables in access 2003 as closely as they did previous versions of the products. One of the most powerful features for me is the grouping function. In excel 2003 if one right clicks date...
8
4871
by: Jerome Ranch | last post by:
Okay So I've got pivot tables setup in Access 2003. Only about 30K records in the current 2005 databases...the pivots summarize the info in a number of nice ways. I need to get the pivot tables into a document so I can distribute the tables, as is, as an electronic report (without the detailed data) So I export to rtf and xls, and I get an error that there is a too much information. I don't want all the data, just the summary table!
3
2399
by: Decreenisi | last post by:
Hi, I have to convert an existing spreadsheet for rejects into an access database. My problem is I use a load of lookup tabels in excel. How do I approch this in access. Also, just a general question, can you do pivot tables in access. Thanks
1
2631
benchpolo
by: benchpolo | last post by:
I have data extracted from Access db to Excel with a pivot table. Somehow, I am having issues with the pivot table were it doesnt update the totals. For example, the first extract i did in Access has 6000 data rows and pivot table in excel should refresh on open and reflect the 6000 data rows. 2nd extract in Access has 10000 data rows when pivot table opens it doesn't refresh the summary count on the pivot table based on the 10000 data...
4
3384
by: drt | last post by:
NEDERLANDS: Hallo, Ik heb eigen functies gemaakt in access, die werken perfect in de access query. Zodra ik echter vanuit excel een draaitabel maakt naar de access query (als een externe database) krijg ik de foutmelding dat er een 'ongedefinieerde functie' in de access database aanwezig is. Kan iemand mij op weg helpen dit probleem op te lossen? Alvast bedankt voor de reactie,
2
9417
by: Gary Dunne | last post by:
Hi All, I'm struggling to find the correct syntax for creating a Pivot table in an excel file via VB . Net 2005 The Excel help file is not particularly helpful where parameters are concerned (It rarely mentiones the required data types etc) The following is as far as I can get; Dim excelApp As Excel.Application
32
23395
by: redman08 | last post by:
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.
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
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
9948
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...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7327
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
6603
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
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.