Solved

Client side VBScript passing parameters to a SQL Server DSN

Posted on 2003-11-23
5
1,200 Views
Last Modified: 2010-05-18
I have a web page that fires client side VBScript. This script initiates a mail merge with a local word document on a locally setup DSN.

I can get the following [extract] to work without parameters:
wrdDoc.MailMerge.OpenDataSource "", , , , , , , , , , , "DSN=MyDSN", "sp_MySproc", , , wdMergeSubTypeWord2000
wrdDoc.MailMerge.Destination = wdSendToNewDocument
wrdDoc.MailMerge.Execute False


Is it possible to pass parameters into the sproc that Im executing?

Thanks..
0
Comment
Question by:niico
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
ambientnet earned 100 total points
ID: 9808327
Have you tried:

wrdDoc.MailMerge.OpenDataSource "", , , , , , , , , , , "DSN=MyDSN", "exec sp_MySproc @Param1='lala', @Param2='lalala'", , , wdMergeSubTypeWord2000
wrdDoc.MailMerge.Destination = wdSendToNewDocument
wrdDoc.MailMerge.Execute False

??

You may also not want to name your procedures with sp_ as a prefix... doing so asks SQL to search the masterdb first, and then your DSN's default database second.

-m
0
 

Author Comment

by:niico
ID: 9811549
Great

Thanks twice for the added sp_ advice - didnt realise that!

I'll check it out and get back to you...
0
 

Author Comment

by:niico
ID: 9838709
Is there any way to define the datatype of each parameter? does it matter in any case?
0
 
LVL 1

Expert Comment

by:ambientnet
ID: 9839966
niico,
     That's an interesting question. Does it matter? That depends on what you're trying to pass. If you're trying to pass strings (char's, varchars, nvarchars etc), then I wouldn't worry about it. If you're trying to pass an Int, I wouldn't worry about it. But you can always open a recordset by way of ADODB.Command and assign Parameters and their Types using the cmdVariable.CreateParameter Method.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdamth01_14.asp   has more information.

But that's a different code structure than what you're trying to do, from what I can see. In that instance, you'd open the "DSN"/Recordset and have your MailMerge Code inside of a Loop.

I'm not sure if you need to go further than 'exec'.. I'd try using your current code and seeing if you run into any problems. My thought is that you won't. ;)
Let me know when things work out!

-m

0
 

Author Comment

by:niico
ID: 9957600
This works well - thanks very much!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

15 Experts available now in Live!

Get 1:1 Help Now