473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Stored proc return codes in Access .ADP

Hey All,
I have am working on an Access Development Project (ADP).
I have developed a SQLSERVER stored proc.
I would like to pass back a return code from the procedure depending on the success and failure of specific parts of a transaction.
I know that I can pass a parameter to the procedure using the following:

Dim cmd As ADODB.Command
Dim intMyID As String

intMyID = 1

Set cmd = New ADODB.Command
With cmd
.ActiveConnection = CurrentProject.Connection
.CommandText = "EXEC Insertallchecklist " & intMyID
.CommandType = adCmdText
.Execute
End With

How do I send a value back to the application, and capture it in my code?

Any help is appreciated.

Scott
Oct 17 '08 #1
2 2740
Hi

The easiest way (at least for me) is to create a stored procedure to write the result in a table and then retrevie the result from the table.

Regards
Emil
Oct 26 '08 #2
ADezii
8,834 Expert 8TB
Hey All,
I have am working on an Access Development Project (ADP).
I have developed a SQLSERVER stored proc.
I would like to pass back a return code from the procedure depending on the success and failure of specific parts of a transaction.
I know that I can pass a parameter to the procedure using the following:

Dim cmd As ADODB.Command
Dim intMyID As String

intMyID = 1

Set cmd = New ADODB.Command
With cmd
.ActiveConnection = CurrentProject.Connection
.CommandText = "EXEC Insertallchecklist " & intMyID
.CommandType = adCmdText
.Execute
End With

How do I send a value back to the application, and capture it in my code?

Any help is appreciated.

Scott
You can return information to a calling Program using a Stored Procedure's Return Value via the Return Statement. When a Stored Procedure processes a RETURN Statement, it unconditionally terminates and sends back the optional Return Value to the calling Program. The Return Value is really a special type of Output Parameter with the name "@return_value". Hopefully, the code below will illustrate this point:
Expand|Select|Wrap|Line Numbers
  1. ‘Example of a Stored Procedure accepting 1 Input Parameter, namely @custid
  2. Create Procedure <procYourProcedureName>
  3.   @custid                 ‘1Input Parameter
  4. As 
  5.   If (SELECT Count(*) FROM tblCustomer WHERE CustomerID = @custid) >= 1
  6.     ‘Success
  7.     RETURN 0
  8.   Else
  9.     ‘Failure
  10.     RETURN 1
Expand|Select|Wrap|Line Numbers
  1. ‘Example of a Sub-Routine that retrieves the Return Value from the Procedure ‘<procYourProcedureName>
  2. Sub <Your Sub Name>(lngCustId As Long)
  3. Dim cnn As ADODB.Connection
  4. Dim cmd As ADODB.Command
  5.  
  6. Set cnn = New ADODB.Connection
  7. Set cmd = New ADODB.Command
  8.  
  9. With cmd
  10.    ActiveConnection = CurrentProject.Connection
  11.   .CommandText = "<procYourProcedureName>”
  12.   .CommandType = adCmdStoredProcedure
  13.   .Parameters.Refresh
  14.   .Parameters(“@custid”) = lngCustId      ‘lngCustId now becomes the Input Parameter for
  15.                                                                   ‘the <procYourProcedureName> Procedure
  16.       .Execute
  17. End With
  18.  
  19. ‘The Return Value is sent back via the ‘@return_value’ Parameter
  20. If cmd.Parameters(“@return_value”) = 0 Then        ‘special type of Output Parameter
  21.   ‘CustomerID lngCustID exists
  22. Else
  23.   ‘CustomerID lngCustID does not exist
  24. End If
  25.  
  26. Set cmd = Nothing
  27. Cnn.Close
  28. Set cnn = Nothing
  29. End Sub
Oct 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: C Kirby | last post by:
In SQL Server 2000, I've got a rather lengthy stored procedure, which creates a lot of temporary tables as it processes down through a few sets of data. When testing it through Query Analyzer, it...
2
by: jaYPee | last post by:
I have an existing query from MS Access that I want to convert it to SQL Server Stored Proc. My problem is on how to convert the WHERE clause. This is the query from MS Access: SELECT...
9
by: Wolfgang Kreuzer | last post by:
Try hard to become familiar with T-SQL. Can anybodey tell me the best way to deal with set's provided by a stored procedure. Til yesterday I thougt trapping set in temp table using INSERT EXEC...
2
by: Rhino | last post by:
I am getting an sqlcode of -927 when I execute SQL within a COBOL stored procedure in DB2 OS/390 Version 6 on OS/390. I have looked at the error message for that condition and tried everything I...
12
by: Jason Huang | last post by:
Hi, In my C# Windows Form application project, I have done all queries on my codes. Now I wanna try using the Stored Procedure. But I am not clear about why using the stored procedure. Would...
3
by: DarkHades | last post by:
Hi all, I have a stored proc which returns twice the result and I dont know why. Can someone have a look at the following code? BTW, I commented the last SELECT/JOIN, cause that one doubled the...
8
by: colmkav | last post by:
Can someone tell me how I can access the return value of a function called from Oracle as opposed to a store proc from oracle? my oracle function is get_num_dates_varposfile. I am only used to...
2
by: Cirene | last post by:
I have a stored proc as follows: ALTER PROCEDURE dbo.GetPostingAuthorId ( @cat int, @Id int, @AuthorId nvarchar(MAX) OUTPUT ) AS IF (@cat = 1) --Classifieds
0
by: mirandacascade | last post by:
Questions toward the bottom of the post. Situation is this: 1) Access 97 2) SQL Server 2000 3) The Access app: a) sets up pass-thru query b) .SQL property of querydef is a string, the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.