Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-15
5
Medium Priority
?
237 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

610 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