Solved

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

Posted on 2014-03-27
7
311 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

691 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