Solved

DoCmd.OutputTo Equivalent

Posted on 2004-08-03
9
3,347 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
[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
  • 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

730 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