Question : How to pass stored procdure return value or Print message to MS Access

Hello,
I've built this stored procedure which seems to work fine, but I want to pass its print message or the return value to be used in MS Access to construct my message back to the user.

I'm currently using: RAISERROR (@StrErrorMsg, 16, 1); to pass my error message, but not getting the results i want and it is taking me to the VBA code when i run by using a button on MS Access.

I treid using Print in SQL and I tried to use RETURN 0 or RETURN @TopCount to return the number of records added using the sp...

Any ideas on how this can be accomplished?

Answer : How to pass stored procdure return value or Print message to MS Access

I took a little different route than originally suggested although using OUTPUT parameters would work too.  This may be a little simpler for you.  See my example below.  You can adapt it to your situation as needed.  Store your error(s) in a local variable as you're doing in your sproc but as your last statement in your proc, use a SELECT statement giving the values an alias to which you can refer in your VBA code.  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
'====  STORED PROC =====
CREATE PROCEDURE MySP 
AS 
 
SELECT 100 As RetValue,  N'Some Err Msg' As RetMsg
 
 
'====  VBA =============
Function AdoReturnTest(cn As ADODB.Connection) As Boolean
   Dim rs As New ADODB.Recordset
   Dim sSQL As String
   sSQL = "Exec MySP"
   rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
   Debug.Print rs!RetValue, rs!RetMsg
   rs.Close
   Set rs = Nothing
End Function
Open in New Window Select All
Random Solutions  
 
programming4us programming4us