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?
LVL 1
Lisa0812Asked:
Who is Participating?
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:

http://www.experts-exchange.com/Databases/MS_Access/Q_21221847.html#12688757

Alan
0
Data-ManCOOCommented:
If you are looking for a non code solution...you 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 out....no code.  If you need to pass parameters when calling the stored proc, use Alan's solution.

Mike
0
Lisa0812Author Commented:
Data-Man,

>If you are looking for a non code solution...you 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)
rs.Close
Set rs = Nothing

 
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Data-ManCOOCommented:
Try this instead

Currentdb.Execute "qtqryGeneric"


Make sure the query is a pass-through query.


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

and yes, this IS  passthrough query!
0
Data-ManCOOCommented:
What is the SQL of the pass through query?

Mike
0
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
)


sptestit
(
  @CusExpiryDate smalldatetime OUTPUT,
  @JoinFee money OUTPUT

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


go


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



Alan
0
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:

pass-through:
execute sp_AddDeliveryDetail  666,222,12


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

AS

INSERT INTO tblDeliveryDetail
 (DeliveryHeaderID, LotDetailID, UserID, DateTimeCreated)
VALUES (@DeliveryHeaderID, @LotDetailID, @UserID,  GETDATE())
GO
0
Data-ManCOOCommented:
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?

Mike
0
sun365Commented:
try

CurrentProject.Connection.Execute "ptqryGeneric"
0

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.