1. If any one knows how to retrieve output parameter from SQL Server Stored Procedure to Access-97 form.
2. How to coach Rrecordset Absolute position (data base SQL Server. Front end Access-97 from).
Thanks.
Here is an Example from an Access Form along with the stored procedure used in the example. This example is doing several things including an output parameter. It is from an Access Project so the connection string is already established.
Option Compare Database
Option Explicit
Public supplyID As Integer
'-- Reference library is "Microsoft ActiveX Data Objects 2.6 Library"
Private Sub Form_Open(Cancel As Integer)
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset, rst2 As New ADODB.Recordset
Dim param1 As Parameter, param2 As Parameter, param0 As Parameter
supplyID = 111
On Error GoTo ErrHandler
' Connect
Set cnn = CurrentProject.Connection
Dim yy As Form
Set yy = Forms!frm_supplier.Form
Set yy.Recordset = rst
Dim cnt As Integer
cnt = 0
While (rst.state = adStateOpen)
Debug.Print "value of rst = "; rst(cnt)
Debug.Print "the Record state = "; rst.state
Debug.Print "the first field = "; rst.Fields(1)
Set rst = rst.NextRecordset(cnt)
cnt = cnt + 1
Wend
Exit Sub
ErrHandler:
Dim er As ADODB.Error
For Each er In cnn.Errors
Debug.Print "err num = "; Err.Number
Debug.Print "err desc = "; Err.Description
Debug.Print "err source = "; Err.Source
Next
End Sub
'STORED PROCEDURE
Alter Procedure "sp_supplier"
(
@supplyid as int,
@supply varchar(20) OUTPUT
)
As
-- The -- is used for commenting in SQL Server or /* comment */
--set nocount on
--insert into customer (custnum, fname, lname,phone,areacode,postcode,state,city,address)
-- Values(553444551, 'Jerry','LastName','7774444','208','888','MN','Duluth','12 sam lane')
select suplrnum, name, address, state from supplier
select count(*) as cnt, state
from supplier
where state is not null
group by state
Sorry, that is going a little deeper into ADO that I have ever needed. I will try to look into it this weekend. Hopefully someone can help you out sooner. Good Luck.
Pat B
Here is a more condensed version using a stored procedure with one output parameter, and no input parameters. The first connection string uses SQL Server security where you have to supply a user and password, the second uses integrated security which uses the user's NT or 2000 login. You can use whichever you prefer, but use only one.
==========
Private Sub GetOutPutParam()
Dim adoCN As ADODB.Connection
Dim adoCMD As ADODB.Command
Dim adoPRM As ADODB.Parameter
Dim myVar As String
Set adoCN = New ADODB.Connection
adoCN.Open strCN
Set adoCMD = New ADODB.Command
With adoCMD
.ActiveConnection = adoCN
.CommandType = adCmdStoredProc
.CommandText = "StoredProcedureNameHere"
Set adoPRM = .CreateParameter("ReturnParam", adVarChar, 50, adParamOutput)
.Parameters.Append adoPRM
.Execute
myVar = .Parameters.Item("ReturnParam"
End With
Set adoPRM = Nothing
Set adoCMD = Nothing
Set adoCN = Nothing
End Sub
==========
This example uses a string variable (myVar) in the code and in the parameter. Now myVar is set to the output parameter, and you can do whatever you want with it. Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.