Solved

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

Posted on 2011-02-15
5
215 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
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
Already figured it out.  Thank you...
0
 
LVL 44

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 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

12 Experts available now in Live!

Get 1:1 Help Now