Error

ohphunk

A Questionnaire
Local time
Tomorrow, 03:17
Joined
Jun 6, 2007
Messages
33
When I was trying to compile a module code, (from allen browne website) there's seems to be an error,

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".NetworkUserName", , False)
Resume Exit_Handler
End Function

So when I compile the code, it says:

Compile error:
Sub or Function not defined.

I've tried the help button, but it only said, only if the

You tried to call a procedure from another project without explicitly adding a reference to that project in the References dialog box.

But I don't know what reference to call.:(
 
Allen references this page of his in every area where he calls it or might call it. Which page of code did you use so I can check it and notify Allen if the reference is missing.
 
I've tried adding "Error Handling in VBA" codes, but have a little trouble of knowing where to put those codes.

And I've tried removing the 4 reference to function LogError(). But still showing the same error.

The "missing reference" was suggested by MS VBA Help.
But this was the code I was using.

Can you tell me where to put the error handling codes?

Thank you so much for helping.:D

Lisa
 
Put the error handling in a standard module and not in a form module.
 
From Allen's site here:
1. Select the Modules tab in the Database Window/Nav Pane. Click New. Access opens a new code window.
2. Copy the code in this link, and paste it into the module.
3. Either remove the four references to function LogError(), or set up error logging as described in Error Handling.
4. Choose Compile from the Debug menu. Fix any errors Access highlights.
5. Save the module with a name such as ajbAudit
So he does have a link to the error handling.
 
Also, if you're logging errors you can pass in the error object and save a little typing on each call. My logger call looks like
Code:
handler:
  LogError Err, Me, "SubOrFunctionName()"
So the logger has full access to the error and the module in which the error occured.
 
sorry for being sucha dufus.:confused:
but where can i find this "standard module"??

I can only see class module.
 
I tried to put the error handling codes in another module.
(Just a trail and error)

But there's a error on wrong expression/invalid character (in red)

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

Just for your info, I'm using MS Access 03, no difference right?
 
A Class Module is part of a form or report. Press F11 to see your full object list (tables, queries, forms, etc.), click on Modules, and then click on "New".

Voila, a standard module, meaning, a module that is its own object, and not a subordinate to an existing object (like a form).
 
Last edited:
I tried to put the error handling codes in another module.
(Just a trail and error)

But there's a error on wrong expression/invalid character (in red)

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

Just for your info, I'm using MS Access 03, no difference right?


You can have a subroutine or a function. You don't have both at once. One can call the other. These are valid:

Sub YourSubroutineName
Function YourFunctionName

These, not so much:
Sub Function YourSubFunctionName
Function Sub YourFunctionSubName

Corrections:

Code:
[u]AS A SUBROUTINE:[/u]

Sub SomeName()
On Error GoTo Err_SomeName ' Initialize error handling.
' Code to do something here.
Exit Sub ' Label to resume after error.

Err_SomeName: ' Label to jump to on error.
MsgBox Err.Number & Err.Description ' Place error handling here.
Resume Next ' Pick up again and quit.
End Sub

[u]AS A FUNCTION:[/u]

Function SomeName()
On Error GoTo Err_SomeName ' Initialize error handling.
' Code to do something here.
Exit Function ' Label to resume after error.

Err_SomeName: ' Label to jump to on error.
MsgBox Err.Number & Err.Description ' Place error handling here.
Resume Next ' Pick up again and quit.
End Function
 
Thanks for the explaination, Moniker.

Another thing, I should change "SomeName" in the modules, am I?
And if I have to change it, what error function name should I change it to?

Thanks again in advance!
 
Thanks for the explaination, Moniker.

Another thing, I should change "SomeName" in the modules, am I?
And if I have to change it, what error function name should I change it to?

Thanks again in advance!

You can use any name, but for simplicity's sake, let's explain it this way:

Code:
Sub BigThingHere()
On Error GoTo Err_BigThingHere

    --- Your variable declarations here ---

    --- Your Code Here ---

    Exit Sub

Err_BigThingHere:
    --- Error Handling Here ---
End Sub

In other words, the simplest way to do this is to add "Err_" to the beginning of your sub or function name, and then throw in the error handling routine at the end of the sub or function. This can become way more sophisticated, but that would just be confusing (I think) at this point.
 
Last edited:
That explainaition helps, a lot.

I hope this is my last question for the day,

I did everything everyone asked me to do on my modules, and compiling the same module, I got an error saying "User-defined type not defined"

Dim db As DAO.Database ' Current database
Dim sSQL As String ' Append query.

Those in red are highlighted when the error appeared.
 
That explainaition helps, a lot.

I hope this is my last question for the day,

I did everything everyone asked me to do on my modules, and compiling the same module, I got an error saying "User-defined type not defined"

Dim db As DAO.Database ' Current database
Dim sSQL As String ' Append query.

Those in red are highlighted when the error appeared.

DAO is a reference library. It's in Tools -> References as "Microsoft DAO 3.6 Object Library". (If your version number is slightly different, that's fine.) Check that box in the references list and it will compile. The error message is telling you that it doesn't know what DAO is because the reference isn't loaded.

A "reference" is a DLL library for all practical purposes; it exposes commands, methods, etc. that aren't available in Access unless 'referenced'. If you scroll through that list, you'll see all sorts of things.

For the record, DAO is "old school" as it were (it's still there for backward compatibility) and is replaced with ADO, but that is a topic for another day. I have to sleep. :)
 
Well, thanks again!!

That helped alot!!:D
Sleep well then.
 
Please don't hit me with a stick.:p

Another error, (I'm not really good at this)

Select Case Err.Number
Case 9999 ' Whatever number you anticipate.
Resume Next ' Use this to just ignore the line.
Case 999
Resume Exit_SomeName ' Use this to give up on the proc.
Case Else ' Any unexpected error.
Call LogError(Err.Number, Err.Description, "SomeName()")
Resume Exit_SomeName
End Select

Error says, "label not defined".
What does that mean??

_________________________________________________________________
(Seems like Access VBA 03 is no use for a rookie like me)
 
Please don't hit me with a stick.:p

Another error, (I'm not really good at this)

Select Case Err.Number
Case 9999 ' Whatever number you anticipate.
Resume Next ' Use this to just ignore the line.
Case 999
Resume Exit_SomeName ' Use this to give up on the proc.
Case Else ' Any unexpected error.
Call LogError(Err.Number, Err.Description, "SomeName()")
Resume Exit_SomeName
End Select

Error says, "label not defined".
What does that mean??

When you tell it to resume and the next keyword isn't "next" (which puts the program on the next line of code past the one that caused the error), it's looking for a label. "Exit_SomeName" is not a defined label. Assuming you have a sub named "SomeName", it would look like this:

Select Case Err.Number
Case 9999 ' Whatever number you anticipate.
Resume Next ' Use this to just ignore the line.
Case 999
MsgBox "Giving up on procedure"
Exit Sub
' Use this to give up on the proc.
Case Else ' Any unexpected error.
Call LogError(Err.Number, Err.Description, "SomeName()")
Exit Sub
End Select
 
I forget to tell you that its a fucntion.:eek:

Because I've tried putting Exit Sub, then compiled it and another error pop-up saying that its a fucntion, not a sub form.

But does it make a difference??
 
Post the whole function from Private Function... to End Function and surround your code with code tags for clarity. {code} {/code} except with [brackets] instead of {braces}.
 
Post the whole function from Private Function... to End Function and surround your code with code tags for clarity. {code} {/code} except with [brackets] instead of {braces}.

Could you show me how?
Not really sure about this.:confused:

Thanks.
 

Users who are viewing this thread

Back
Top Bottom