| Chat with a LIVE Microsoft
Access Expert! |
||||
|
||||
|
#1
|
||||
|
||||
|
Return Errors to Table
I've been working on some update utilities which I've figured out pretty well, but I'd like some better error trapping. These utilities are being e-mailed out to the various locations (not connected by a common LAN & not web-based) and I'd like to create a table listing any errors received during the update so I can see exactly where the problem lies.
I found this thread which looks like what I need, but I can't can't find how to do it. Code:
Funtion ImportTextFiles() --this would be whatever your function name is On Error Goto Err_ImportTextFiles 'Below is a snippet of my code--the whole utility uses this delete/import design DoCmd.DeleteObject acQuery, "Employee Query" DoCmd.TransferDatabase acImport, "Microsoft Access", strPath, acTable, "Employee List TableXXX", "Employee List TableXXX", False Exit_ImportTextFiles: Exit Function Err_ImportTextFiles: Select Case Err.Number Case 3011 *do something here if you want to log the error *don't use a msgbox as it will stop the code and wait for the *user to click OK Resume Next Case Else Resume Exit_ImportTextFiles End Select End Function If, for instance, Access can't find the object "Employee Table" I receive the error# 3011 (or error# 7874 for the DeleteObject line), can I have Access enter the object name into a table? If this can be done, then I can simply make some code to export the table and then create an email for the user to send the file back to me. |
| Sponsored Links |
|
#2
|
||||
|
||||
|
You need to do 3 things.
1.. Create a table 2.. Add a function 3.. Alter code in each form error code. 1.. tblErrors fields: ErrorID -> AutoNumber ErrorTime -> Date/Time ErrorNumber -> Text ErrorDescription -> Memo SubRoutine -> Text FormName -> Text 2.. Create a new module. Public Sub ErrorHandler(ByVal lngError As Long, ByVal strError As String, _ ByVal strSub As String, ByVal strForm As String) On Error GoTo Err_ErrorHandler Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("tblErrors") With rs .AddNew !ErrorTime = Now() !ErrorNumber = lngError !ErrorDescription = strError !SubRoutine = strSub !FormName = strForm .Update .Close End With Set rs = Nothing Set db = Nothing 'If you dont want a message comment out the following line MsgBox "Error " & lngError & " has occured. " & strError, vbCritical, " Error" Exit_ErrorHandler: Exit Sub Err_ErrorHandler: MsgBox "An error has occurred in the Error Handling Routine." & vbCrLf & vbCrLf & _ Err.Description, vbExclamation, " ASSETSonTRACK" Resume Exit_ErrorHandler End Sub 3.. Alter the forms error handling Called from the form routine cmdSales_Click as follows: 'Call ErrorHandler(Err.Number, Err.Description, "cmdSales_Click", Me.Name) Dave
__________________
Apathy is on the increase, but who cares. Imagine if there were no hypothetical questions
|
|
#3
|
||||
|
||||
|
PS
You will also need to reference Microsoft DAO 3.6
__________________
Apathy is on the increase, but who cares. Imagine if there were no hypothetical questions
|
|
#4
|
||||
|
||||
|
That looks like it'll return the error number and description to a table. That's not quite what I'm looking for.
The update database I made uses a LOT of delete/import lines: Code:
DoCmd.DeleteObject acQuery, "NameOfQuery1" DoCmd.DeleteObject acQuery, "NameOfQuery2" DoCmd.DeleteObject acQuery, "NameOfQuery3" DoCmd.TransferDatabase acImport, "Microsoft Access", strPath, acQuery, "NameOfOldQuery1", "NameOfNewQuery1a", False DoCmd.TransferDatabase acImport, "Microsoft Access", strPath, acQuery, "NameOfOldQuery2", "NameOfNewQuery2a", False So, I'm basically looking for a way to return the object name or the whole line of code where the error occurred. That way it's easy to tell where the code stopped, and therefore, which objects remain to be updated. I've tested, pretty thoroughly, the updates w/ copies of the off-site databases, but I'm trying to error on the side of caution. |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| table layout for airport minicab quote system | antonyx | Tables | 7 | 08-30-2009 10:44 AM |
| Working on design tutorial | Kraj | Theory and practice of database design | 29 | 08-11-2006 09:40 AM |
| Need some suggestions on table layouts | chad101 | Tables | 16 | 01-08-2006 01:01 PM |
| Yet another relationships question | XQuestion | Tables | 5 | 09-09-2005 11:38 AM |
| Creating a form that updates a table, only if data is not already in the table | vexing | Forms | 1 | 04-26-2001 10:52 AM |