Solved

DoCmd.OutputTo Equivalent

Posted on 2004-08-03
9
3,338 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Determine next b-weekly date 12 56
MS SQL Backup 24 70
SQL Server memory Issue 7 74
SQL Server 2012 Row Selection 2 29
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

705 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

20 Experts available now in Live!

Get 1:1 Help Now