• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1122
  • Last Modified:

Pass-Through queries with OUTPUT parameters

I would like to read an output parameter from a SQL stored procedure that I am calling from an MS Access Linked Front End via a pass-through query.

I am opening up an ado recordset using the pass-through which returns the records if criteria is met, however when criteria is not met, I am setting a 'Return_Cde' and 'Return_Msg' output params to messages used by the FE. I am not able to figure out how to reference the output parameter defined in the sp.

Pass-Through Returns Records property set to true.

  • 2
  • 2
1 Solution
Here is an example: See if you can adopt in your scenario.
scalar function, checks a parameter value and returns a value.
if object_id(N'ufn_Scalar',N'FN') is not null
	drop function ufn_Scalar;
create function dbo.ufn_Scalar (@parameter_name AS nvarchar(25))
RETURNS nvarchar(25)
with execute as caller
	declare @parameter_out nvarchar(25)
	if @parameter_name='1' 
		set @parameter_out='The value is 1'
		set @parameter_out='The value is not 1'
	RETURN (@parameter_out)

Open in new window

Here is a pass-through query in Access front end: When you run it, asks you for the DSN
SELECT dbo.ufn_Scalar('2');
'The value is not 1

Open in new window

Howiee22Author Commented:
Thanks. I will give this a try. One thing I was able to determine, is if I open an ADO recordset  to the results of the sp, then I am not able to read the output parameter. If I close the recordset, then I can access the value of the parameter as set in the sp. Is there another way to approach this as to being able to read output AND continue using the recordset?
If you can help in creating the issue, I might be able to answer.
Try to send the sql to create a table in MSSQL, and a simple Access FE.
Howiee22Author Commented:
Hi, sorry for not getting back to this... From what I was able to determine, once you close the recordset object, I am able to access the output/return variables.
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.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now