Solved

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

Posted on 2011-02-15
5
218 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-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now