Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to call SQL Stored procedure in Outlook form

Status
Not open for further replies.

csudougie

MIS
Dec 15, 2006
37
Hello,

I'm having trouble getting my vbscript to execute a SQL stored procedure over an ODBC connection from an Outlook form.

The s.p. only accepts one integer and returns a string value. Can anyone help me with the syntax or point me in a direction. I've looked into pass-through queries, but they want to run in VB and the funtions I've found don't like vbscript.

Thanks.

Option Explicit
dim rc, sql, cnn

sub OpenConn()
dim dsn
set cnn = CreateObject("ADODB.Connection")
dsn = "Provider=sqloledb;Data Source=MAJ_LINKED_TABLES;"
cnn.Open dsn
SQL = "{EXECUTE dbo.GET_CUS_NAME_fn(myvalue)}"
end sub

Sub cmdTest_Click()

dim objPage, objControl
dim s
dim MyValue
Set objPage = Item.GetInspector.ModifiedFormPages("Message")
Set objControl = objPage.Controls("txt_So")
MyValue = objControl.Value
OpenConn()
rc = cnn.Execute (SQL)
msgbox rc
end sub
 
csudougie,
I think it's a syntax issue, the way I read it your passing the the string '[tt]myvalue[/tt]' to the SP.

Code:
sub OpenConn()
dim dsn
set cnn = CreateObject("ADODB.Connection")
dsn = "Provider=sqloledb;Data Source=MAJ_LINKED_TABLES;"
cnn.Open dsn       
'[s][red]SQL = "{EXECUTE dbo.GET_CUS_NAME_fn(myvalue)}"[/red][/s]
end sub

Sub cmdTest_Click()

dim objPage, objControl
dim s
dim MyValue
Set objPage = Item.GetInspector.ModifiedFormPages("Message")
Set objControl = objPage.Controls("txt_So")
MyValue = objControl.Value
OpenConn()
rc = cnn.Execute([red]"{EXECUTE dbo.GET_CUS_NAME_fn[b](" & MyValue & ")[/b]}"[/red])
msgbox rc
end sub

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top