Solved

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

Posted on 2014-03-27
7
310 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 400 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
Technology Partners: 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 37

Assisted Solution

by:PatHartman
PatHartman earned 100 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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