?
Solved

Export Access Report to Excel using VB

Posted on 2006-07-17
5
Medium Priority
?
392 Views
Last Modified: 2013-12-25
Hi,

Just wondering could you solve a little problem for me.
I am having trouble exporting data from an Access Report to an excel file using VB and hitting a brick wall. Any help would be much apprecicated.

Thanks in advance.
0
Comment
Question by:cstephen100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17123419
>I am having trouble exporting data from an Access Report to an excel file using VB
Just so you know, exporting an Access Report anywhere usually means all of the cosmetic formatting gets messed up.
A better idea would be to export the report's record source (table or query) into Excel, where all of the cosmetic formatting is already in place.

Dim oAccess As Access.Application
Set oAccess = CreateObject("Access.Application")
 oAccess.OpenAccessProject "drive"\your_database.mdb"
oAccess.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "Table Name", "File Name.xls"
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 600 total points
ID: 17127633
(slight corrections)
oAccess.OpenAccessProject "c:\your_database.mdb"   'The full drive, path, and file name goes here

Also Substitute acSpreadsheetTypeExcel97 with whatever version you are running... (97-Excel 97, 8=2000, 9-XP, 10-2003)
0
 
LVL 11

Assisted Solution

by:pootle_flump
pootle_flump earned 400 total points
ID: 17128559
Jim is spot on. Reports tend to export pretty terribly, especially to excel and especially if you have even the simplest groupings set up. However the code to do so would be:

oAccess.DoCmd.OpenReport "MyReportName", acViewPreview
oAccess.DoCmd.RunCommand acCmdOutputToRTF

HTH
0
 
LVL 11

Expert Comment

by:pootle_flump
ID: 17128603
Doh - I posted the word export.

Apols it should be acCmdOutputToExcel
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17143998
Hi cstephen100

Let us know if you need any more help or advice.

Thanks.
-Jim
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question