Tracking Errors

  • Thread starter Thread starter Lucky
  • Start date Start date
L

Lucky

I need to create an error log table (I call it
tblErrorLog with 3 fields: ErrorDate (Date/Time set to
default Now(), ErrorSource (Text, 255), ErrorDescription
(Memo)) and track in this table every error that occurs.

As such, I need to create code that will save (append)
the error source and error description into table while
clearing the error in the process and resume action.

Any help is greatly appreciated.
 
See:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

The article explains how to:
- create a suitable;
- write a generic error routine to log the errors;
- call the routine from each of your procedures;
- optionally show or not show the error to the user.
 
Thank you for your suggestion.

I have used your example, it works fine, but
unfortunately I am unable to write to the error log table
as I get the following message:
Unable to records because Error 13
Type mismatch.

I have checked and rechecked my code for misspelling,
etc., but everything seems to be in order (if you would
like I can paste it in next message). I plan to use it
in Access 2000.

Any ideas what could cause this?

Thank you.

Lucky
 
Which line generates this error?

If it is:
Dim rst As Recordset
try replacing it with:
Dim rst As DAO.Recordset

You need a reference to the DAO library. From the code window, choose
References on the Tools menu, and check the box beside:
Microsoft DAO 3.6 Library.
More information about references:
http://allenbrowne.com/ser-38.html

Please post back if this is not the line that generates the error.
 
Yes,

That was it (the DAO.Recordset; I was already referencing
the library). After I changed it, everything worked
fine.

Now I need to update all my code. That will take some
time. I will let you know if I encounter any more errors.

Thank you for your help.

Sincerely,

Lucky

P.S. Just a quick question. Is this possible to do with
ADO, rather then DAO (all of my code is in ADO)?

And by the way, how is the weather in Perth. Your city
seems like a great place to live (from the pictures I
have seen when WRC was there).
 
Couple of suggestions. The clash comes because the DAO library (default in
A97 and earlier) has a Recordset object, and so does the ADO library
(default in A2000 and later). You can solve this with any of the following:

1. If you are not actually using the ADO library, uncheck the box beside:
Microsoft ActiveX Data Objects (ADO) 2.xx
That's the simplest and best approach.

2. Perform a Search'n'Replace in your code. Search for:
As Recordset
and replace with:
As DAO.Recordset
Save all the modules, and the change is done.

Do both if appropriate.
 
I have rectified the error by changing the code to ADO.
As such, I have used example from your website and
replaced the following code

Dim rst As DAO.Recordset 'Table <Table>

'Open table tbl_ErrorLog
Set rst = CurrentDb.OpenRecordset("<Table>")

rst.Close
Set rst = Nothing

with this one (showing just changes).

Dim cnn As ADODB.Connection 'Current db
Dim rst As New ADODB.Recordset 'Table <Table>

'Open table <Table>
Set cnn = CurrentProject.Connection
rst.Open "<Table>", cnn, adOpenKeyset,
adLockOptimistic

rst.Close
Set rst = Nothing
cnn.Close
Set cnn = Nothing

It worked great in test and I have now employed it in my
update sequence. I will let you know if I will encounter
any more errors.

Sincerely,

Lucky
 
Back
Top