473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Exporting s Stored Procedure to Excel

Hi,

A simple question but, is it possible to export a stored Procedure to excel using the docmd.TransferSpreadsheet function?

If not, what is the easiest way to accomplish this?
Sep 24 '08 #1
10 9258
Stewart Ross
2,545 Expert Mod 2GB
Welcome to Bytes, Darkside.

Visual Basic for Applications procedures cannot be transferred using the TransferSpreadsheet method. Access VBA code is stored in code modules within the database, and similarly user-defined VBA procedures in Excel are stored in code modules within the workbook itself.

When TransferSpreadsheet is used to export data to Excel it transfers the results of the query concerned, not the underlying method of calculation. It is equivalent to pasting values into an Excel sheet.

Whilst it is possible to export and import complete code modules (not individual procedures) between Access and Excel doing so automatically requires VBA coding. It is more involved than I can show here at present.

If the task is one-off it is much easier to do this manually from the VBA environment window in each application (in Access to export the code module concerned, and in Excel to import the module into the workbook).

It does not take long to do such an import, although it may then prove necessary to adapt or rewrite the Access code to fit the different environment of an Excel workbook - this can be quite a time-consuming task, depending on how much or little of the code has to be changed.

-Stewart
Sep 24 '08 #2
Hi Stewart,

Probably should have explained the problem more thoroughly.

I have an Access Project database linked to SQL Server. I'm trying to create a loop that will change the variable in a stored procedure each time through the loop and then output the results to excel.

Creating the code to generate the procedure was no problem but..... exporting the procedures output to excel is proving more difficult. I tried creating a from that used the procedure as a datasource and then outputting the form but got the same results as trying to export the procedure directly.

I have noticed however that I can export tables in access project using the docmd.transferspreadsheet method.

So, is it feasible to modify my sql to generate a table each time through the loop (I can just delete the table after export). Or is there a simpler way that I'm missing.

Any help you can give me would be greatly appreciated

Dark
Sep 24 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi Dark. Sure, within a loop you can generate an SQL string of the form "SELECT ... INTO sometable", then run this using either the Execute or RunSQL methods to generate the table. You can use TransferSpreadsheet on the temporary table on each pass through the loop without a problem, although you would need to vary the output name on each occasion (or you will just overwrite the last output on each successive pass).

I'm still unclear what you are referring to when you use the term 'stored procedure', since it is clearly not VBA code you are meaning; do you mean a set of operations (somewhat like an Access macro)? Or are you meaning an SQL query, where you supply some form of parameter?

-Stewart
Sep 24 '08 #4
ADezii
8,834 Expert 8TB
Hi Stewart,

Probably should have explained the problem more thoroughly.

I have an Access Project database linked to SQL Server. I'm trying to create a loop that will change the variable in a stored procedure each time through the loop and then output the results to excel.

Creating the code to generate the procedure was no problem but..... exporting the procedures output to excel is proving more difficult. I tried creating a from that used the procedure as a datasource and then outputting the form but got the same results as trying to export the procedure directly.

I have noticed however that I can export tables in access project using the docmd.transferspreadsheet method.

So, is it feasible to modify my sql to generate a table each time through the loop (I can just delete the table after export). Or is there a simpler way that I'm missing.

Any help you can give me would be greatly appreciated

Dark
This should point you in the right direction. The following code will Export the Stored Procedure named procTestExport, in an Access Project, to Microsoft Excel Format, specifically to Test Stored Procedure.xls in the C:\Test\ Directory.
Expand|Select|Wrap|Line Numbers
  1. Dim strOutputPath As String
  2.  
  3. strOutputPath = "C:\Test\Test Stored Procedure.xls"
  4.  
  5. DoCmd.OutputTo acStoredProcedure, "procTestExport", "MicrosoftExcel(*.xls)", strOutputPath, False, ""
P.S. - It will not AutoStart Excel in the Export Process (the False Argument)
Sep 24 '08 #5
Cheers Guys,

Figured there was a simple way of doing it. You've just saved one of my friends from having to run the same query 7903 times lol.

Thanks again,

Dark
Sep 24 '08 #6
ADezii
8,834 Expert 8TB
Cheers Guys,

Figured there was a simple way of doing it. You've just saved one of my friends from having to run the same query 7903 times lol.

Thanks again,

Dark
You are quite welcome.
Sep 24 '08 #7
NeoPa
32,556 Expert Mod 16PB
Probably should have explained the problem more thoroughly.
Considering your later replies are so much clearer I won't labour the point, but yes. Your first post wasn't the most clear ;)

@Stewart, A Stored Procedure is a SQL Server term referring to a piece of stored (and pre-optimised) T-SQL code (can include variables etc) which returns a CURSOR or recordset. A bit like a SQL Server VIEW.

Linking an Access database to a SQL Server Stored Procedure treats it as a linked table.
Sep 25 '08 #8
Stewart Ross
2,545 Expert Mod 2GB
Thanks ADezii and NeoPa for the assistance, and apologies Dark if my posts were less of assistance than they should have been.

Gesh, the term 'stored procedure' confuses me anyway. I would never have guessed it was an SQL procedure package used by SQL Server, but then I don't develop client-server apps in SQL-Server. I live and learn.

Cheers

Stewart
Sep 25 '08 #9
ADezii
8,834 Expert 8TB
Thanks ADezii and NeoPa for the assistance, and apologies Dark if my posts were less of assistance than they should have been.

Gesh, the term 'stored procedure' confuses me anyway. I would never have guessed it was an SQL procedure package used by SQL Server, but then I don't develop client-server apps in SQL-Server. I live and learn.

Cheers

Stewart
You know the way it goes, Stewart. I watch your back - you watch mine - and we both watch NeoPa's. (LOL).
Sep 25 '08 #10
NeoPa
32,556 Expert Mod 16PB
@tyrdrannoy
This is not related to the original question of the thread so must be posted as a separate thread (http://bytes.com/topic/access/answer...r-entered-data). I will move it for you and create the links so that you can find it again.
Jan 6 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mike | last post by:
Hello, I'm currently working on debugging a very large DTS package that was created by someone else for the purpose of importing data into my company's database. The data is mainly...
5
by: Anthony | last post by:
First time here so please bear with me. Set up a DTS package to export data to an excel sheet on an hourly basis. Problem is, it keeps appending to the same excel sheet. Any idea how to...
0
by: franjorge | last post by:
Hi, I have created two stored procedures via VB using this code: sql = "CREATE PROC " & nombre_proc & " AS SELECT *" & _ " From MBM_PUNTOS_SCE_SIN_COINCIDIR_SIEGE_FALTA_PM_NE_" & mes & _ "...
0
by: jabernet | last post by:
As importing/exporting data ist not directly supported for JDBC/SQLJ, we call a c-stored procedure which uses the administrative API for exporting/importing. Now with the newest DB2 8.1 Fixpack...
1
by: activeashish | last post by:
Can any one help me out for exporting stored procedure in MYSQL Do stored procedure come under any database?
0
by: Mariana | last post by:
Hello, I am exporting reports in pdf format from .net 2005 . The export is working fine; however the user values of stored procedure parameters does not show in the report. What do I need to do in...
3
dbushcmohle
by: dbushcmohle | last post by:
Hello, I am having problems exporting a stored procedure's results to an Excel file... I've done this many times successfully, but never had to introduce a variable. Now that I've introduced...
7
by: flickimp | last post by:
Hi I want to create a Stored Procedure in SQL with three variables that are declared in an Excel file. Thus, when the user enters the three variables into Cells A1, B1, C1 Then hits a...
1
by: flickimp | last post by:
Hi I have a stored procedure on SQL Server 2000 called: .Capacity_Planning.dbo.sp_flickimp_test I have an Excel Sheet with the 2 paramters for the Stored procedure in cells A1 and B1. How...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.