jordanking
Programmer
- Sep 8, 2005
- 351
Hello,
I am developing some advanced error handling for a database. I have a sql server back end and a adp front end. I have built a function that takes error data and inserts it into a sql table for tracking. What I want to do is have a form open on non critical errors that the user can add notes or descriptions to the error tracking record.
The problem is: I am having trouble passing data between the two from modules.
from the documentation, the err object is cleared once you reach a end sub or end function. So I tried to create a public custom data type containing the error information. But it only existis within its module.
I want this error form to be able to be called from any other form in the adp.
so I created this code to catach an error and open the error form:
this opens the error form for logging errors. The global err object is still available to the first sub or function that executes on the newly opened form. I have code in the on open event:
the err number is printed correctly. However, if the error was generated by an external application, say sql server, and it returned error information, I want to be able to assign that info the the err object, or create another custom object (ie: Public Type DMS_Error) with the same global scope of the err object. I could then assign the values of that object to hidden text fields on the form during the open event, which could then be refrenced by the
Private Sub cmdExit_Click(), which adds the users description to the information and initiates my error Record insert in sql server(DMS_ErrorLog)
or they may be a way easier way to accomplish all this.
Any help would be appreciated.
I am developing some advanced error handling for a database. I have a sql server back end and a adp front end. I have built a function that takes error data and inserts it into a sql table for tracking. What I want to do is have a form open on non critical errors that the user can add notes or descriptions to the error tracking record.
The problem is: I am having trouble passing data between the two from modules.
from the documentation, the err object is cleared once you reach a end sub or end function. So I tried to create a public custom data type containing the error information. But it only existis within its module.
I want this error form to be able to be called from any other form in the adp.
so I created this code to catach an error and open the error form:
Code:
Private Sub cmdSearch_Click()
Dim iRet As Integer
On Error GoTo ErrLog
'main code goes here
' Raise the overflow error
err.Raise 6
Exit_Sub:
Exit Sub
ErrLog:
DoCmd.OpenForm "frmErrorLog"
Resume Exit_Sub
End Sub
this opens the error form for logging errors. The global err object is still available to the first sub or function that executes on the newly opened form. I have code in the on open event:
Code:
Option Explicit
Public Type DMS_Error
intVBAError As Integer
chrVBADescription As String
chrSource As String
chrSQLState As String
intNativeError As Integer
chrNativeDescription As String
intEmployeeID As Integer
chrUserName As String
chrStation As String
intRecType As Integer
intAction As Integer
intAuditID As Integer
chrNote As String
End Type
Private Sub cmdExit_Click()
Dim strNotes As String
Dim iRet As Integer
strNotes = Nz(Me.chrNote, "")
iRet = DMS_ErrorLog("sqlState", 0, "native Description", rtCustomer, atUpdate, 777, strNotes)
Debug.Print "POINT 3 Err#: " & err.Number
DoCmd.Close
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
Dim rsConfig As New ADODB.Recordset
Dim sqlConfig As String
Dim strVersion As String
Me.lblNumber.Caption = err.Number
Me.lblDescription.Caption = err.Description
'initialise connection string and open connection
cnn.ConnectionString = [Forms]!frmSwitchboard!xProvider & [Forms]!frmSwitchboard!xDataSource
cnn.Open
sqlConfig = "SELECT chrVersion FROM dbo.DMS_Config WHERE intConfigID = 1"
rsConfig.Open sqlConfig, cnn, adOpenStatic
Me.lblVersion.Caption = rsConfig.Fields("chrVersion")
Me.lblCopy.Caption = Chr(169) & " 2005 - " & CStr(Format(Date, "yyyy"))
Me.chrNote.SetFocus
' Close the connection.
cnn.Close
Debug.Print err.Number
End Sub
the err number is printed correctly. However, if the error was generated by an external application, say sql server, and it returned error information, I want to be able to assign that info the the err object, or create another custom object (ie: Public Type DMS_Error) with the same global scope of the err object. I could then assign the values of that object to hidden text fields on the form during the open event, which could then be refrenced by the
Private Sub cmdExit_Click(), which adds the users description to the information and initiates my error Record insert in sql server(DMS_ErrorLog)
or they may be a way easier way to accomplish all this.
Any help would be appreciated.