[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Exporting MS Access Query to Excel

Posted on 2013-01-16
9
Medium Priority
?
303 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 48

Expert Comment

by:Dale Fye
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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 48

Expert Comment

by:Dale Fye
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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

649 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