wow thanks so much that was exactly what i was looking 4
just to clear something up thou (iv only been doing access programming
for a month lol), is the code placed like this: ?
====this code will be put before every function===
Sub|Function SomeName()
On Error GoTo Err_SomeName ' Initialize error handling.
' Code to do something here.
Exit_SomeName: ' Label to resume after error.
Exit Sub|Function ' Exit before error handler.
Err_SomeName: ' Label to jump to on error.
MsgBox Err.Number & Err.Description ' Place error handling here.
Resume Exit_SomeName ' Pick up again and quit.
End Sub|Function
===this code is put once off somewhere in the db?===
Function LogError(ByVal lngErrNumber As Long, ByVal strErrDescription
As String, _
strCallingProc As String, Optional vParameters, Optional bShowUser
As Boolean = True) As Boolean
On Error GoTo Err_LogError
' Purpose: Generic error handler.
' Logs errors to table "tLogError".
' Arguments: lngErrNumber - value of Err.Number
' strErrDescription - value of Err.Description
' strCallingProc - name of sub|function that generated the error.
' vParameters - optional string: List of parameters to record.
' bShowUser - optional boolean: If False, suppresses display.
' Author: Allen Browne, (e-mail address removed)
Dim strMsg As String ' String for display in MsgBox
Dim rst As DAO.Recordset ' The tLogError table
Select Case lngErrNumber
Case 0
Debug.Print strCallingProc & " called error 0."
Case 2501 ' Cancelled
'Do nothing.
Case 3314, 2101, 2115 ' Can't save.
If bShowUser Then
strMsg = "Record cannot be saved at this time." & vbCrLf &
_
"Complete the entry, or press <Esc> to undo."
MsgBox strMsg, vbExclamation, strCallingProc
End If
Case Else
If bShowUser Then
strMsg = "Error " & lngErrNumber & ": " & strErrDescription
MsgBox strMsg, vbExclamation, strCallingProc
End If
Set rst = CurrentDb.OpenRecordset("tLogError", , dbAppendOnly)
rst.AddNew
rst![ErrNumber] = lngErrNumber
rst![ErrDescription] = Left$(strErrDescription, 255)
rst![ErrDate] = Now()
rst![CallingProc] = strCallingProc
rst![UserName] = CurrentUser()
rst![ShowUser] = bShowUser
If Not IsMissing(vParameters) Then
rst![Parameters] = Left(vParameters, 255)
End If
rst.Update
rst.Close
LogError = True
End Select
Exit_LogError:
Set rst = Nothing
Exit Function
Err_LogError:
strMsg = "An unexpected situation arose in your program." & vbCrLf
& _
"Please write down the following details:" & vbCrLf & vbCrLf &
_
"Calling Proc: " & strCallingProc & vbCrLf & _
"Error Number " & lngErrNumber & vbCrLf & strErrDescription &
vbCrLf & vbCrLf & _
"Unable to record because Error " & Err.Number & vbCrLf &
Err.Description
MsgBox strMsg, vbCritical, "LogError()"
Resume Exit_LogError
End Function
sorz still getting the hang of programming and how everything works
many thanks for the quick reply btw
-soulfather-
Allen said:
You will need to:
a) create the table to hold the errors (so you can export it), and
b) create a generic function to handle the errors, and
c) call the function in the error handler of each procedure of your
database, and
d) ensure you use the Error event of the form to trap the engine-level
errors.
There's an example of how to set up such a table and function here:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html
hi all
i am currently having difficulty with something i need to impliment
into my companies database asap
here is a checklist of what i need to achieve
1) write global code that will make MSACCESS send all the errors that
happen in the database to a table (err.description, err.number, etc)
2) here is the code i have to export this data (once it is in the
table) to a txtfile for the I.T department to see what the clients
problem is
-----> DoCmd.OutputTo acOutputTable, "errorlog", acFormatTXT,
"errorlog.txt"
with this implimentation it will save hours of travelling time to and
from clients as they can just email the company their "error log" and
then we can see exactly what the prob is... and im sure this is an
interesting concept for other DB programmers to look at using as it is
a big time saver.