Solved

Exporting MS Access Query to Excel

Posted on 2013-01-16
9
299 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
[X]
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
  • 4
  • 3
  • 2
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

737 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