Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 19th, 2003, 06:33 PM
Registered User
 
Join Date: Nov 2003
Location: , , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling Stored procedures with out parameters

I have an access 2000 adp project with an SQL 2000 backend server, I am trying to call a stored procedure with an input and output parameter. My store procedures look like this:

Alter Procedure prcCHK
    (
        @cuid as int,
        @pts as char(10) output
    )
As
select top 1 @pts=pts from tblp1 where custid=@cuid
return

my access procedure look like

   Dim CustomerID As Integer
   Dim pts As String
   CustomerID = 3065
   Set dblocal = CurrentProject.Connection
   dblocal.Execute ("prcCHK" & "'" & CustID & "' , '" & pts & "'")

All I want the code to do is call the stored procedure "prcCHK" and for it to return the a single value 'pts'

I have checked the syntax and it work fine outside of access (SQL Query Analyser) but does not when called from the access code. Any suggestions on how I can get the stored procedure to return a single value to the calling access procedure/function.

  #2 (permalink)  
Old November 25th, 2003, 04:30 PM
Registered User
 
Join Date: Nov 2003
Location: , MN, .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had trouble with that too so I worked around it. I don't remember the order in which I discovered things but the first thing to try (if you haven't already) is add this line to your stored proc:
SET NOCOUNT ON

If that doesn't work, my work-around was to scrap the output parameter and instead have the last line of the proc be a select statement. Then in VBA open a recordset and grab that field.

Example:
In store proc last line is:
SELECT @RetMsg AS RetMsg


In Access:
        strSQL = "EXEC uspMySproc " & _
            Me!ItemVendorNumber

        Set cmd = New ADODB.Command
        With cmd
            .ActiveConnection = CurrentProject.Connection
            .CommandText = strSQL
            .CommandType = adCmdText
            .CommandTimeout = 2400
            Set rst = .Execute
        End With
        Set cmd = Nothing

        strStatus = Nz(rst.Fields("RetMsg"))

This has worked for me every time.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling AS/400 Stored Procedures from VB.NET prasanthknair ADO.NET 0 January 19th, 2005 06:55 AM
Calling Oracle Stored Procedures booksnore2 General .NET 0 August 24th, 2004 02:08 PM
SQL Pass though parameters to stored procedures blinton25 SQL Server 2000 3 March 29th, 2004 02:49 PM
in-line parameters in stored procedures itekcorp ADO.NET 0 July 12th, 2003 09:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.