ACC1x: Trapping SQL Server RAISERROR() Function ValuesID: Q101678
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
Microsoft SQL Server users often create triggers or stored procedures that
perform specific functions which are fired during certain events. Often, a
custom-generated error value is desired to indicate the status of such
events. This article describes a way to trap that value in Microsoft
Access.
NOTE: This article assumes that the user is running Microsoft Access
version 1.1, because that version corrects a problem to allow the SQL
Server RAISERROR() function to return a value to Microsoft Access.
CREATE PROCEDURE TestProc
AS
RAISERROR 25000 'This is a test error'
CREATE TRIGGER TestTrig
ON Authors
FOR UPDATE
AS
EXECUTE TestProc
Sub TrapIt ()
Dim db As Database, Mydyna As Dynaset
Dim Xerr As String, Xval As Integer,
Dim Xstart As Integer, Xlen As Integer
On Error GoTo ErrorHandler
Set db = CurrentDB()
Set Mydyna = db.CreateDynaset("select * from dbo_authors;")
Mydyna.Edit
Mydyna!au_fname = Mydyna!au_fname
Mydyna.Update
Mydyna.MoveNext
Exit Sub
ErrorHandler:
'This routine parses the error string returned from ODBC and
'extracts only the error value you assigned with the RAISERROR()
'function in SQL Server.
'traps the error message
xerror = Error$
'finds start of error value
Xstart = InStr(1, xerror, "#") + 1
'finds length of error value
Xlen = InStr(Xstart, xerror, ")") - Xstart
'extracts error value from string
Xval = Mid(xerror, Xstart, Xlen)
MsgBox ("You have encountered error #" & CStr(Xval))
Resume Next
End Sub
Keywords : kb3rdparty IsmPdox
Version : 1.1
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: March 25, 1999