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
Solved

Export Access Report to Excel using VB

Posted on 2006-07-17
5
372 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
  • 3
  • 2
5 Comments
 
LVL 65

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 65

Accepted Solution

by:
Jim Horn earned 150 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 100 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 65

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

790 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