Solved

Export Access Report to Excel using VB

Posted on 2006-07-17
5
343 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now