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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call SQL Stored Procedure from Access 97 2

Status
Not open for further replies.

alexyo7

Programmer
Jan 26, 2004
7
US
I'm trying to call a SQL Server stored procedure from an Access 97 database. I tried looking through the old threads and found a few items related to stored procedures, but nothing that clearly answered my question.

The Stored Procedure is called ProcCreateCase, and it is expecting to paramaters: Param1, Param2.

Could someone please show me the code required to call that stored procedure with the two paramaters when the user pushes the command button?

Thanks in advance!

Alex
 
What are you going to do with the data returned? Does the the result need to be bound to a Form? Is the result returned to a recordset that is processed internally - unbound?
 
I mainly just need to pass the paramaters and run the procedure, so that a bunch of work can take place on the SQL server. I'm not really expecting anything back. Maybe a success/failure flag at most.
 
Use the ADO Command. I am doing this from memory at work, but have many examples at home. If this does not work I will check back when I get home. If you encounter an error be explicit with the description.


'-- Reference Library
'-- Microsoft ActiveX data objects 2.6 library needed for ADO
Dim cn As New adodb.Connection
Dim rs As adodb.Recordset, connString As String
connString = "provider=SQLOLEDB.1;" & _
"User ID=sa;Initial Catalog=pubs;" & _
"Data Source=bigtuna;" & _
"Persist Security Info=False"
cn.ConnectionString = connString
cn.Open connString

Dim cmd As New adodb.Command
Dim Parm1 as adodb.Parameter, parm2 as adodb.Parameter

Set parm1 = cmd.CreateParameter("parm1", _ adInteger, adParamInput)
Set parm2 = cmd.CreateParameter("parm2", _ adVarchar, adParamInput, 20)

cmd.CommandType = adCmdStoredProc
cmd.CommandText = "ProcCreateCase"
cmd.ActiveConnection = cn
cmd.Execute

cn.Close
Set cn = Nothing

 
I forgot the part about adding the parm to the Parameters collection and assigning the values.

Set parm1 = cmd.CreateParameter("parm1", _ adInteger, adParamInput)
cmd.Parameters.Append parm1
parm1.Value = 77

Set parm2 = cmd.CreateParameter("parm2", _ adVarchar, adParamInput, 20)
cmd.Parameters.Append parm2
parm2.Value = "abc"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top