Solved

Export Access Report to Excel using VB

Posted on 2006-07-17
5
379 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

713 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