Hi,
I have a function log_error that logs errors into a table. But I can't get it to work. This is the function:
Function log_error(user As String, error_nr As Integer, error_descript As String, active_object As String)
On Error GoTo error_trap
Dim cnn As Connection
Dim rst As New ADODB.Recordset
Dim x As Integer
Set cnn = CurrentProject.Connection
cnn.BeginTrans
DisplayMessage (Date & " en " & Time & " en " & CurrentUser & " en " & Err.Number & " en " & Err.Description & " en " & Screen.ActiveControl)
rst.open "tbl_STD_errorlog", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
rst.AddNew
rst!datum = Date
rst!tijd = Time
rst!user = CurrentUser
rst!error_nr = error_nr
rst!error_descript = error_descript
rst!active_object = active_object
rst.Update
cnn.CommitTrans
x = MsgBox("This program has become an error. Please warn your system administrator", vbCritical, "Meerkerk Ledensysteem Error"
Exit_form:
Exit Function
error_trap:
cnn.RollbackTrans
MsgBox Err.Description
Resume Exit_form
End Function
and this is how I call the function:
log_error(CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie"
It seems right, not? But I get a compile error saying: 'expected =', but the function haven't got a return value set. So I changed the function call in
Function log_error(user As String, error_nr As Integer, error_descript As String, active_object As String) as Integer
and used:
Dim x as Integer
x = log_error(CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie"
then, when I compile, I got a warning 'types don't match' and log_error is highlighted.
What's wrong?
greetz
Tom
I have a function log_error that logs errors into a table. But I can't get it to work. This is the function:
Function log_error(user As String, error_nr As Integer, error_descript As String, active_object As String)
On Error GoTo error_trap
Dim cnn As Connection
Dim rst As New ADODB.Recordset
Dim x As Integer
Set cnn = CurrentProject.Connection
cnn.BeginTrans
DisplayMessage (Date & " en " & Time & " en " & CurrentUser & " en " & Err.Number & " en " & Err.Description & " en " & Screen.ActiveControl)
rst.open "tbl_STD_errorlog", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
rst.AddNew
rst!datum = Date
rst!tijd = Time
rst!user = CurrentUser
rst!error_nr = error_nr
rst!error_descript = error_descript
rst!active_object = active_object
rst.Update
cnn.CommitTrans
x = MsgBox("This program has become an error. Please warn your system administrator", vbCritical, "Meerkerk Ledensysteem Error"
Exit_form:
Exit Function
error_trap:
cnn.RollbackTrans
MsgBox Err.Description
Resume Exit_form
End Function
and this is how I call the function:
log_error(CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie"
It seems right, not? But I get a compile error saying: 'expected =', but the function haven't got a return value set. So I changed the function call in
Function log_error(user As String, error_nr As Integer, error_descript As String, active_object As String) as Integer
and used:
Dim x as Integer
x = log_error(CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie"
then, when I compile, I got a warning 'types don't match' and log_error is highlighted.
What's wrong?
greetz
Tom