We help IT Professionals succeed at work.
Get Started

Using SQL Stored Procedure From Access VB Code

232 Views
Last Modified: 2015-07-15
I am a long time Access user but a complete NUB to using a SQL Server back end.  

From with SQL I created my first Stored Procedure called 'dbo.spMJO1st'.  This is it:

USE [GRBImportSSMA]
GO
/****** Object:  StoredProcedure [dbo].[spMJO1st]    Script Date: 7/13/2015 11:28:09 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spMJO1st] 
AS

BEGIN


    -- Insert statements for procedure here
	SELECT NumberOfPayments, AmountOfPayments, DateTimeOfBatch
	from dbo.tblBatchPaymentLog
	order by NumberOfPayments
END

Open in new window


There are about 90 records in the table.

As you can see, It is very simple.  It select 3 fields from a SQL table and puts them in order by one of the fields.  At least I think it does.

I have a routine in my Access app that reads a table and goes thru all entries.  for the purposes of this question, that's all it does.

This is the processing loop:

'
selectString = " Select * From  tblBatchPaymentLog "

Dim rsIn2 As ADODB.Recordset
Set rsIn2 = New ADODB.Recordset
rsIn2.Open selectString, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'
If rsIn2.EOF Then
    '
Else
    If rsIn2.RecordCount > 0 Then
        '
        '
        While Not rsIn2.EOF
            '
            '
            rsIn2.MoveNext
        Wend
            
    End If
End If
'
rsIn2.Close
Set rsIn2 = Nothing

Open in new window


I would like to revise the processing loop  to use the result set from the stored procedure instead of the Access table.

How do I change the ADO commands to accomplish this?

.
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE