Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I get a return value from stored procedure with a call from access?

Posted on 2011-02-15
5
223 Views
Last Modified: 2012-05-11
Hello

Below is a function I have in Access to fire a stored Procedure in SQL Server 2005.  I am missing something to return the value that my Stored Procedure is getting.  Help.

Public Function SQLWrapper()
Dim strSQL As String
Dim cnn As New ADODB.Connection
Dim ProcName
 
   ProcName = "EXEC  [dbo].GetQuoteNumber] ""StartTime"", ""Lonnie"", ""Wilson"", ""2/2/2011"",""ST"" "
   With cnn
       .ConnectionString = "ODBC;PROVIDER=SQLOLEDB; blah blah balh
       .Open
       .Execute ProcName
   End With
 
Exit Function
0
Comment
Question by:LSpiker
  • 3
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
ID: 34898325
Assuming the stored procedure is a query that returns a recordset, maybe the .ReturnRecords property has been turned off.  

After:  .ConnectionString = "ODBC;PROVIDER=SQLOLEDB; blah blah balh

Insert:  .ReturnRecords = True
0
 

Author Comment

by:LSpiker
ID: 34898655
GRayL

Well that didn't work but here is my stored procedure.  Think anything is wrong here?


USE [MWS_SPARTA]
GO
/****** Object:  StoredProcedure [dbo].[GetQuoteNumber]    Script Date: 02/15/2011 12:11:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:            Lonnie Spiker
-- Create date: 2/14/2011
-- Description:      This gets the starting position and length of red line
-- =============================================
ALTER PROCEDURE [dbo].[GetQuoteNumber]
      -- Add the parameters for the stored procedure here
      @CtlSource as varchar(25), @Fname as varchar(25) ,@Lname as varchar(25) ,@WODate as date, @RetVal as varchar(50)
      
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

    -- Insert statements for procedure here
      SELECT t.SchedNumOfHours FROM tblScheduleCal t WHERE EmpFName =  @FNAME  AND  EmpLName = @Lname AND WODate = @WODate;
      
      Return
               
      END
      
      
0
 

Author Comment

by:LSpiker
ID: 34898780

here is my updated vb code in accesss

Public Function SQLWrapper() As String
Dim strSQL As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.recordset
Dim ProcName
 
   Set cnn = New ADODB.Connection
   Set rs = New ADODB.recordset
 
   ProcName = "DECLARE @Return_value int EXEC @Return_Value = [dbo].[GetQuoteNumber] ""StartTime"", ""Lonnie"", ""Wilson"", ""2/2/2011"",""ST"" SELECT ""Return Value"" = @return_value"
   With cnn
       .ConnectionString = "ODBC;PROVIDER= Blah blah blah
       .Open
   End With
   rs.Open ProcName, cnn
   If Not rs.EOF Then
      SQLWrapper = rs("SchedStartTime")
   End If

End Function
 
0
 

Author Comment

by:LSpiker
ID: 34900601
Already figured it out.  Thank you...
0
 
LVL 44

Expert Comment

by:GRayL
ID: 34903090
Great, now show us what you did and you get your points back.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

839 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