?
Solved

What is the best way to export the results of a query to excel or csv

Posted on 2014-03-27
7
Medium Priority
?
312 Views
Last Modified: 2014-04-06
If I have a query, for example "Stock Requirements" or "Bill of Materials" what is the best way to export the results to an excel or csv file to a folder on the local C:\MyFolder drive. Hopefully without over-riding any existing file.

I would like to have a button on the main form that exports it without a load of questions

Derek
0
Comment
Question by:DatabaseDek
[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
7 Comments
 
LVL 5

Expert Comment

by:Pasha Kravtsov
ID: 39959415
Create a view with your sql query and then build a SSIS Package to export the data automatically via SQL Server Agent.

Edit: Sorry forgot to switch it to Expert Comment
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1600 total points
ID: 39959456
to export to excel

docmd.transferspreadsheet acexport,, "Stock Requirements", "C:\MyFolder\myExcel.xls", True


what version of office are you using ?
0
 

Author Comment

by:DatabaseDek
ID: 39959483
This is for an application that is packaged and goes out as an mde so it will have to work with all versions.

I suspect the old .xls will do. Is that what you are referring too?

Derek
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39959565
ok, the code above should work.. try it and post back the result
0
 
LVL 38

Assisted Solution

by:PatHartman
PatHartman earned 400 total points
ID: 39960424
You need to make the destination a variable or you will keep overwriting the existing file and you probably want to do it in two parts.  Part 1 gets the path.  If this changes frequently, you should prompt for it each time.  If it is generally fixed for a user, then it should be stored in a table as part of a setup.  That way the user can choose the location once and not be prompted each time but still have the ability to go back and change the default location.  The second part is the file name.  You may want to include the date as a suffix or perhaps something else to make it unique.
0
 

Author Comment

by:DatabaseDek
ID: 39961173
I will try code and variable and post back.

Many thanks

Dere
0
 

Author Closing Comment

by:DatabaseDek
ID: 39981452
Sorry took so long to come back.

Works a treat and I have a variable for the path

Thanks to you both

Derek
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…
Suggested Courses

752 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