Solved

DoCmd.OutputTo Equivalent

Posted on 2004-08-03
9
3,342 Views
Last Modified: 2012-06-27
In access, I have a front end form, listing query names (some parameter queries), user makes a selection, selects output format and I use DoCmd.OutputTo to dump the query to the selected output
Very easy.
These queries are essentially a dump of data acting as simple reports.

Now that I have upgraded to using SQL server, I have made these queries into stored procedures, some taking parameters.

Question is, I dont think I can use DoCmd.OutputTo, due to the parameters in the stored procedures, does anyone know of a equivalent? I was looking for a quick way to run a query, passing in parameters and dump to a selected output.

Or is this a case of having to create a ADO recordset, read thru records and dump contents into a file.


0
Comment
Question by:rockiroads
  • 4
  • 3
  • 2
9 Comments
 
LVL 10

Expert Comment

by:imrancs
ID: 11702891
try this

Dim @Str varchar(4000)
Set @Str = 'bcp "Exec SP_NAME"  QueryOut c:\output.txt -c -S<Server> -U<UserName> -P<Password> -t,'
Exec master..xp_cmdshell @Str

Imran
0
 
LVL 65

Author Comment

by:rockiroads
ID: 11703627
I need the code in VBA, is that possible?

0
 
LVL 10

Expert Comment

by:imrancs
ID: 11712630
>>Now that I have upgraded to using SQL server, I have made these queries into stored procedures, some taking parameters.<<

According to your above statement I understand that you have move your queries to MS SQL Stored Procedures. If so then simply put the above code into an SP and excute it from you VBA code.


Imran
0
 
LVL 5

Accepted Solution

by:
Krys_Wilson earned 250 total points
ID: 11726794
Rocki,

Sorry it took me so long to get to this question.  If you are using an ADP front end, you can use DoCmd.OutputTo for stored procedures.  I checked VBA for a mdb as well and the option for acStoredProcedure is in there as well.

Here is the VBA code I used and it created a quick little test file.  It seems to work best to output to excel though.

DoCmd.OutputTo acStoredProcedure, "sp_test", "MicrosoftExcel(*.xls)", "C:\TestSP.xls", False, ""

Let me know how that works for you!

Chris
0
Backup Your Microsoft Windows Server®

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

 
LVL 5

Expert Comment

by:Krys_Wilson
ID: 11726843
Oh, also Rocki I almost forgot, I created that code by creating a macro using the OutputTo action.  Then I converted the macro to code.

Just for more clarification:

"sp_test" - Name of my stored procedure
"MicrosoftExcel(*.xls)" - Name of the output type
"C:\TestSP.xls" - Name of the file to output to
"False" - Autostart the application after the output command has run
"" - Name of template file used or none in this case.

HTH

Chris
0
 
LVL 65

Author Comment

by:rockiroads
ID: 11727527
I'll give it a go, thanks

r u still around, if so post a response to this now
0
 
LVL 65

Author Comment

by:rockiroads
ID: 11727563
great, it works, I was worried about the parameters, but it prompts you for it, so thats no problem

thats makes a life a lot easier for me, I thought it might not be compatible, I should of checked huh,

thanks man

0
 
LVL 5

Expert Comment

by:Krys_Wilson
ID: 11728138
Yep, Im still here and Ill check back in a bit.

Im heading to a meeting from 10 am to 11 am here in a bit. (Its 9.51 am now).

Glad it worked for you!

Chris
0
 
LVL 65

Author Comment

by:rockiroads
ID: 11728217
ok, wanted to award u summat for the help u gave me earlier

pls see this
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21083661.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

920 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

16 Experts available now in Live!

Get 1:1 Help Now