Solved

Exporting MS Access Query to Excel

Posted on 2013-01-16
9
293 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

743 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

13 Experts available now in Live!

Get 1:1 Help Now