?
Solved

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

Posted on 2011-02-15
5
Medium Priority
?
231 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
[X]
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
  • 3
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
GRayL earned 2000 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

800 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