Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DoCmd.OutputTo Equivalent

Posted on 2004-08-03
9
Medium Priority
?
3,353 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Accepted Solution

by:
Krys_Wilson earned 1000 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
 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

772 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