Stored Procedure from Access?

How can I run  from Access a stored procedure that does not return records (like an insert), and how do I run a sp that has a return value and get the return value in Access?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alan WarrenApplications DeveloperCommented:
Hi Lisa,

check this post:
 a few ways here:

If you are looking for a non code can create a pass through query, put the name of the stored proc as the SQL, set the ODBC connection string and the returns records to No.

Alan's solution are perfect, mine if kind of the easy way code.  If you need to pass parameters when calling the stored proc, use Alan's solution.

Lisa0812Author Commented:

>If you are looking for a non code can create a pass through query, put the name of the stored proc as the SQL, set >the ODBC connection string and the returns records to No.

yes, this is what I was trying to do. But
when I try running (Do.Cmdrunsql) the pass-through which calls a sp that does an Insert I get this error:
run-time error 3129
Invalid SQL statement; expected DELETE, INSERT, PROCEDURE, SELECT, or UPDATE

The query that returns a value I did get working with this code:

this is the code that I was trying to run the sp that has a return value.
it is acutaly trying to run a pass-through procedure that contains this line:
declare @a bigint execute AmountAvailPieces 2090, @AvailPieces = @a output select @a

Dim db  As dao.Database
Dim rs  As dao.recordSet
Set db = CurrentDb
Set rs = db.OpenRecordset("ptqryGeneric") 'this is the pt query that calles the sp
AmountAvailPiecesForItem = rs(0)
Set rs = Nothing

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Try this instead

Currentdb.Execute "qtqryGeneric"

Make sure the query is a pass-through query.

Lisa0812Author Commented:
I tried this and I get -
Run-time Error 3065
Cannot execute a select query

and yes, this IS  passthrough query!
What is the SQL of the pass through query?

Alan WarrenApplications DeveloperCommented:
Hi Lisa,

Can you post the sub proc 'AmountAvailPieces' please and the calling proc ptqryGeneric

here is an example of calling a stored proc from a stored proc returning outputparms from the nested proc to the caller.

In the caller I Declare variable
In the target (nested) proc the params are declared in the first line

ALTER   procedure spGetJoinFee
  @CusID int,
  @CusExpiryDate smalldatetime OUTPUT,
  @JoinFee money OUTPUT

  @CusExpiryDate smalldatetime OUTPUT,
  @JoinFee money OUTPUT

EXECUTE spGetJoinFee @CusID,
                     @CusExpiryDate = @CusExpiryDate OUTPUT,
                     @JoinFee = @JoinFee OUTPUT


JoinFee will be returned from the child proc to the parent proc and then to the app that executes the parent proc.

Lisa0812Author Commented:
I don't have a problem with the query that returns a value, as I mentioned in a previous comment that this I go working.

But the insert query is the one that I can't run. Here is the pass-through and the sp:

execute sp_AddDeliveryDetail  666,222,12

CREATE PROCEDURE sp_AddDeliveryDetail @DeliveryHeaderID bigint, @LotDetailID bigint, @UserID int


INSERT INTO tblDeliveryDetail
 (DeliveryHeaderID, LotDetailID, UserID, DateTimeCreated)
VALUES (@DeliveryHeaderID, @LotDetailID, @UserID,  GETDATE())
What happens if you double click on the pass-through query...does it run?  

I'm not trying to insult your intelligence, but did you change the query to be a pass-through?


CurrentProject.Connection.Execute "ptqryGeneric"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.