Solved

Exporting MS Access Query to Excel

Posted on 2013-01-16
9
294 Views
Last Modified: 2013-07-07
I have a query created in MS Access that I would like to export to Excel.  Can you provide me with the VBA code which will export the query to Excel, save it to a specific location on my network drive and automatically open it for viewing?   Thanks.
0
Comment
Question by:alpha100
  • 4
  • 3
  • 2
9 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38784439
to export the query to excel, use this line

for A2007 and above
docmd.transferspreadsheet acexport, 10, "queryName", "C:\FolderName\Myexcel.xlsx", true


for A2003
docmd.transferspreadsheet acexport, 8, "queryName", "C:\FolderName\Myexcel.xls", true
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38784450
to open the excel file

shell "excel.exe C:\FolderName\Myexcel.xls"
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38784477
The OutputTo method will also do this:

docmd.OutputTo acOutputQuery, "queryName", "acFormatXLSX", [OptionalFileName], True

If you don't enter the output format (acFormatXLSX) it will popup a dialog that allows you to select your output format.  If you don't include a file name, it will popup the FileOpenSave dialog.  The True argument opens the file in it's native format.
0
 

Author Comment

by:alpha100
ID: 38788209
Can you provide me with the step by step instructions on accessing the VBA module in Access?   Thanks.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38788231
open your db
hit ALT + F11
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38788248
1. Open a form in design view

2. Add a command button (turn off the control wizard or you will get the wizard solution).

3. Right click on the button and display the properties window.

4. In the Events tab, find the click event.  Expand the dropdown at the end of that line and select [Event Procedure], then click the "..." to the right of the dropdown.  That will open the VBA window.  (the other way to open the VBA window is Ctrl-G).

5.  Copy the code I gave you above into the click event of the control, making the appropriate changes to "queryName"

go back to your form and view it in form view.
0
 

Author Comment

by:alpha100
ID: 38828751
Can you only perform this in a form or can you do this from your switchboard?
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 38828786
depending on what switchboard you have..

better if you upload a copy of the db.
0
 

Author Comment

by:alpha100
ID: 39305433
Thanks so much for your assistance
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 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

22 Experts available now in Live!

Get 1:1 Help Now