Solved

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

Posted on 2014-03-27
7
306 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
7 Comments
 
LVL 5

Expert Comment

by:Pasha Kravtsov
Comment Utility
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 119

Accepted Solution

by:
Rey Obrero earned 400 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
ok, the code above should work.. try it and post back the result
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 100 total points
Comment Utility
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
Comment Utility
I will try code and variable and post back.

Many thanks

Dere
0
 

Author Closing Comment

by:DatabaseDek
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now