473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Code for query to "Export to Excel" as pivot

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?
Nov 13 '05 #1
3 11879
If you want an Excel Pivot table as your end result, forget it!

I suggest trying this:

1) Get back to the base query (forget the crosstab in Access)

2) Export it to Excel

3) In that Excel file, turn on the macro recorder, and record yourself making
the pivot table

4) Use the code created in step 3 insdie of an Access module, using
CreateObject("Excel.Application") and automation from there.
Nov 13 '05 #2
> 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.
Sure! A 'crosstab' in Access is a 'pivot table' in Excel.
Does this code exist? Is it transferspreadsheet but with a twist?


The code doesn't exist - you'll have to write it. Here's a really
high-level version of what you're going to do:

Use OLE Automation / ActiveX to program Excel through Access VBA
( set up a reference, then dim xl as new excel.application or
something )

Copy all of the data into an Excel worksheet, from the query your
crosstab is BASED ON. Using code, like xl.workbooks(0).cells(y,
x).text = the value from your query.

Then recreate the pivot in Excel, through your code, and save the file
( again through code ).

Otherwise, your options are to take the list/dump you're getting now,
or do your analysis in Access. Writing out your own code really won't
be that hard, though...
Nov 13 '05 #3
Could you post on how this is done with the Pivot table, if you get it
working successfully? I've been trying to do something very similar
and haven't been able to come up with something that I can be happy
with.

I have a docmd.transferspreadsheet command that is exporting to Excel,
the only problem is that the Excel spreadsheet is completely
unformatted and the columns are too small in width (which I can live
with I guess). I recorded a Macro in Excel and tried to use Access to
run it, but some of it works and some of it doesn't.

Dim xls As Object
Set xls = CreateObject("Excel.Application")
xls.Application.Visible = True
xls.Workbooks.Open (path & filename)

'Works
'Freeze Top Pane
xls.Rows("2:2").Select
xls.ActiveWindow.FreezePanes = True

'Doesn't work
'Background color of first row (with fieldnames) to gray
xls.Rows("1:1").Select
xls.Selection.Interior.ColorIndex = 15
xls.Selection.Interior.Pattern = xlSolid
xls.Selection.Interior.PatternColorIndex = xlAutomatic

I'm not sure why the first part works but the 2nd part doesn't. The
code was recorded using the macro recorder in Excel 2000 and copied
and pasted into Access 2000. Any ideas? Thanks.
dc****@aol.comSPNOAM (DCM Fan) wrote in message news:<20***************************@mb-m25.aol.com>...
If you want an Excel Pivot table as your end result, forget it!

I suggest trying this:

1) Get back to the base query (forget the crosstab in Access)

2) Export it to Excel

3) In that Excel file, turn on the macro recorder, and record yourself making
the pivot table

4) Use the code created in step 3 insdie of an Access module, using
CreateObject("Excel.Application") and automation from there.

Nov 13 '05 #4

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

Similar topics

13
by: DarkSpy | last post by:
many c++ compilers including "gcc" have not implemented the "export" keyword, but the comeau compilers made it (just i knew). i want to know about: is it too difficult to implement "export"...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
1
by: matthew kramer | last post by:
Hi, I'm using the reverse pivot technique on an excel spreadsheet to create a list dataset from which I can make a pivot table in excell. The only problem is that because there are so many...
1
by: NS3687 | last post by:
Hi, Is there a way to simulate the Excel Pivot table flexibility in MS Access? I mean, once I get the needed data into one table, instead of writing one query to for an analysis point, I'd lke to...
0
by: Bill Stock | last post by:
I'm rebuilding a query for some Excel Pivot Tables, loading the Excel Workbook and then running a macro in the Excel WB to rebuild the dynamic column names. This all works, except that sometimes...
2
by: amrhi | last post by:
Hello Guys,....! Can you help me how to export my table to excell using php code ..? thanks alot
2
by: MMak12 | last post by:
Hi, I have generated pivot table using perl and getting data from database. I have two rows, pivot table automaticaly calculate the total for each row. I want remove the total for one row and...
15
by: r90slash6 | last post by:
Hi Guys, I have code for click event on an Access form that opens an Excel file, refreshes data of a pivot table on the active worksheet and then filters records based on a criteria. Everything...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.