error logs

A

Afrosheen

I'm starting to set up a routine to log errors. I was looking at Allen
Brown's routine and would like to incorporate it in my program. What I need
to know is how to set it up. I've looked at his program and it's kinda
confusing to me. Bare in mind that I've only been using access for about a
month so what goes where or how its triggered is baffling. I do have the
regular error handing codes within the procedure. I was just wondering if the
function part of his program goes in to a module and how to call the module
on error.

I hope someone can explain it to me.

Thanks for reading my post.
 
T

Tom van Stiphout

On Fri, 4 Jul 2008 04:24:01 -0700, Afrosheen

Are you talking about this page:
http://www.allenbrowne.com/ser-23a.html

The function LogError goes in a standard module.
The page has an example of how to call it:
Call LogError(Err.Number, Err.Description, "SomeName()")

-Tom.
 
T

Tom van Stiphout

On Sat, 5 Jul 2008 00:20:02 +0800, "Allen Browne"

Your function is called like this:
Call LogError(Err.Number, Err.Description, "SomeName()")
Personally I would not pass in the Err.Number and Description. The Err
object is global so the function can read these values itself.
In the occasional case you want a different description you could code
that as:
Err.Description = Err.Description & " My additional text goes here"
Call LogError(Err.Number, Err.Description, "SomeName()")

-Tom.
 
A

Afrosheen

Thanks for the info. Thanks to Allen also for the routine. I'll try and apply
it. I'll try and follow it. I already have the module and the table set up.
So now it's just incorporating it. I'll try and set up one prodedure and get
that working then redo the other procedures. In fact here is one of the
procedures.

Private Sub Form_Current()
On Error GoTo Form_Current_Error

If trainer = True Then
cmdtoggle.Enabled = True
Else
cmdtoggle.Enabled = False
End If

On Error GoTo 0
Exit Sub

Form_Current_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
Form_Current of VBA Document Form_frm_emergency"
End Sub

I have other people than me running the program so I wanted something that
would keep track of the errors and tell me if there was a problem.

Thanks again..
 
A

Afrosheen

Update:
I created an error and this is what I got: Compile Error. Expected variable
or procedure, not module.

Here is the code:
Private Sub Form_Open(Cancel As Integer)
' fld = True
On Error GoTo Form_Open_Error

x = y
domd.help

On Error GoTo 0
Exit Sub

Form_Open_Error:
Call LogError(Err.Number, Err.Description, "form_open()")
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
Form_Open of VBA Document Form_frm_emergency"
End Sub
 
A

Allen Browne

Thanks, Tom, for the suggestion.

I would have to think through the implications of what you are saying.
Benefits of *not* passing the error number and description would include the
fact that the Err object is already global, and supports mulitple errors
within it. What concerns me is the possibility that another error could
occur, so that the current error is not the one that originally occurred.
That was the point of copying the Err.Number and Err.Description from the
Err object to the variables before passing it.

Could that happen? I don't know. VBA is not multi-threaded, but JET is. Is
there a chance that it could it fail in some future version of Access? We
are certainly moving towards multi-core machines, and the software will go
that way. VBA is unlikely to be re-written to be multi-threaded, but VBA
calls in JET are not uncommon.

So, I just don't know if it would be 100% reliable or not. It seemed to me
that the safest path was to copy the error info to variable before anything
else happened.

Any further suggestions welcome.
 
A

Allen Browne

The error message suggests that you have a module with the same name as the
procedure. Try renaming the module to something else, e.g. "Module1".

Then try Compile on the Debug menu (in the code window.)

I'm also unsure of what domd.help does.
 
A

Afrosheen

Hi Allen, Thanks for getting back to me.
I changed the module name to moderror. I ran the procedure under debug and
still came up with the error. I took out the domnd.help. I created that for
the error.

Private Sub Form_Open(Cancel As Integer)
' fld = True
On Error GoTo Form_Open_Error

x = y


On Error GoTo 0
Exit Sub

Form_Open_Error:
Call moderror(Err.Number, Err.Description, "somename()")
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
Form_Open of VBA Document Form_frm_emergency"
End Sub


Where the "somename()" is is that supposed to be the name of the procedure?

Thanks again. Your help is appreciated.
 
A

Allen Browne

You got the *same* error message after renaming the module?

Try a compact/repair (in case the old name is hanging around.)

If that doesn't solve it, there must be another naming clash in the database
somewhere or you would not get that same error message.
 
A

Afrosheen

Hi Allen,
Sorry I haven't got back to you sooner. I did get the program working. Thanks.
I have another question for you concerning the routine. It came up with the
window.

Please write down the following details, etc. The error was error#424 Object
required. Unable to record because Error 3265. Item not found in this
collection.


I looked in the table for the error and there was not there. Is it supposed
to write the error or does it work off the case statement. If it works off
the case statements, then I take it I have to put the case number in it
correct?

Case 3314, 2104 and so on?

If possible I would like it to write the errors to the table because the
people using it are going to be data entry people and won't know how to fix
the problems.

Thanks again
 
A

Allen Browne

That means an error occurred in the LogError() function.

Temporarily disable the error handling in this function, by adding a single
quote to the 2nd line, i.e.:
'On Error GoTo Err_LogError
You will then be able to see which line caused the error.
That will let you know what item was not found.
Perhaps you don't have a table named tLogError?
Or perhaps you don't have a field named ErrNumber?
Or ...
 
A

Afrosheen

Hi Allen,
Thanks again for the help. It's people like you that I can count on for help.

I did find the problem. In the tLogError table, I had description spelled
wrong and CallingProc with a space in between Calling and Proc.

Thanks again. I'll mark the post that it was answered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top