[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Stored Procedure from Access?

Posted on 2004-11-28
10
Medium Priority
?
15,811 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:Lisa0812
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12690195
Hi Lisa,

check this post:
 a few ways here:

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

Alan
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 12690436
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
 
LVL 1

Author Comment

by:Lisa0812
ID: 12690664
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Data-Man
ID: 12690824
Try this instead

Currentdb.Execute "qtqryGeneric"


Make sure the query is a pass-through query.


Mike
0
 
LVL 1

Author Comment

by:Lisa0812
ID: 12691958
I tried this and I get -
Run-time Error 3065
Cannot execute a select query

and yes, this IS  passthrough query!
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 12692336
What is the SQL of the pass through query?

Mike
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12692529
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
 
LVL 1

Author Comment

by:Lisa0812
ID: 12693129
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
 
LVL 18

Expert Comment

by:Data-Man
ID: 12695928
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
 
LVL 2

Accepted Solution

by:
sun365 earned 200 total points
ID: 12697235
try

CurrentProject.Connection.Execute "ptqryGeneric"
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

872 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