Option Compare Database
Option Explicit
'Compiled in Access 2003, 04-Sept-2013
'REFERENCES NEEDED:
'
'Visual Basic For Applications
'Microsoft Access 11.0 Object Library
'Microsoft DAO 3.6 Object Library
'OLE Automation
'Microsoft ActiveX Data Objects 2.8 Library
Public Const SPROC As String = "ISCenter_Monitor.usp_log_ISCenter_Event"
Public Const ConnStr = _
"Driver={SQL Server};Server=AQL02;database=TRACI_ANALYTICS;UID=;PWD="
Public Sub ErrorLogger()
Dim EventID As Long
Dim RowsAffected As Long
Dim ErrorMessage As String
Dim AdditionalInfo As String
Dim StepSucceeded As Integer
On Error GoTo PROC_ERROR
RowsAffected = 999
ErrorMessage = "Test Error Message #003"
AdditionalInfo = "Testing from MS Access VBA/ADODB"
StepSucceeded = 1
EventID = OpenErrorLogger()
If EventID <> 0 Then UpdateErrorLog EventID, RowsAffected, _
ErrorMessage, AdditionalInfo, StepSucceeded
MsgBox "EventID was " + CStr(EventID)
GoTo PROC_EXIT
PROC_ERROR:
MsgBox Err.Description
Resume PROC_EXIT
PROC_EXIT:
End Sub
Public Function OpenErrorLogger() As Long
On Error GoTo PROC_ERROR
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim EventID As Long
EventID = 0
conn.ConnectionString = ConnStr
conn.Open
With cmd
.ActiveConnection = conn
.CommandType = adCmdStoredProc
.CommandText = SPROC
.NamedParameters = True
.Parameters("@EventName").Value = "Test Event"
.Parameters("@ModuleName").Value = "Test Module"
.Parameters("@ProcedureName").Value = "Test Procedure"
End With
cmd.Execute
EventID = cmd.Parameters("@RETURN_VALUE").Value
GoTo PROC_EXIT
PROC_ERROR:
MsgBox Err.Description
Resume PROC_EXIT
PROC_EXIT:
On Error Resume Next
conn.Close
OpenErrorLogger = EventID
End Function
Public Sub UpdateErrorLog(EventID As Long, RowsAffected As Long, ErrMsg _
As String, AdditionalInfo As String, StepSucceeded As Integer)
On Error GoTo PROC_ERROR
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
conn.ConnectionString = ConnStr
conn.Open
With cmd
.ActiveConnection = conn
.CommandType = adCmdStoredProc
.CommandText = SPROC
.NamedParameters = True
.Parameters("@EventID").Value = EventID
.Parameters("@ErrorMessage").Value = ErrMsg
.Parameters("@StepSucceeded").Value = StepSucceeded
.Parameters("@AffectedRows").Value = RowsAffected
.Parameters("@AdditionalInfo").Value = AdditionalInfo
End With
cmd.Execute
GoTo PROC_EXIT
PROC_ERROR:
MsgBox Err.Description
Resume PROC_EXIT
PROC_EXIT:
On Error Resume Next
conn.Close
End Sub
ASKER
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY
If your looking for some slick error handling, take a look at vbaWatchDog:
http://www.everythingaccess.com/vbwatchdog/installation.htm
It hooks right into VBA and provides global error handling.
Jim.