Solved

DoCmd.OutputTo Equivalent

Posted on 2004-08-03
9
3,348 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

690 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