Which line did error occur on?

RichO

Registered Yoozer
Local time
Yesterday, 20:09
Joined
Jan 14, 2004
Messages
1,036
Hey guys,

I have a piece of VBA code that handles certain errors and then resumes execution. Lately it is giving me an error and because of the error handling routine, I can't rely on the standard access error dialog with the debug button to direct me to the source of the error.

Step debugging is not an option because it cycles through this code hundreds of times.

How can I find the source (line) of the error?

Is there a way to still get the debug button when the error handler encounters an error it isn't written to handle?

Thanks!
 
Step your VBE's Preferences to "Break on all Errors" then you will get a standard error dialog regardless of whether you have an Error Handling routine and can go directly to that line.
 
And, another way (one that I frequently use) in case you know which procedure it is occuring on but don't know what it is, I just comment out the On Error GoTo line and then I get the dialog with the Debug button.
 
Thanks for your replies...

The problem is that I need the error handler to process and handle error number 5 and then resume running. If I break on all errors or disable the error handling, it never gets to the error that I'm trying to fix.

So there is no way to do this....

Code:
If Err.Number=5 Then
     (handle this error)
Else
     (give me the standard error dialog)
End If

Thanks again.
 
First of all, why are you needing to handle an error 5? Second, I'm assuming that you are guaranteed an error 5 when running your code, so why can't you fix it so you don't get the error to begin with?
 
Break on all errors at least will point you to correct line of problem, then you can put a breakpoint on the same line, then reset the VBE's preferences and you can now then step through the code with error handling.
 
Actually, I didn't write this piece of code. It was written by a previous employee.

The code works with a collection, something I have no experience working with, so I don't know how to fix the error 5 problem. This is what the error handler is doing:

Code:
CDJJobCount_Error:
   If Err.Number = 5 Then
      Set objCnt = New CDJCount
      objCnt.StageName = strTemp
      colEmps.Add objCnt, Key:=strTemp
      If blnOff Then
         Resume NewOff
      ElseIf blnSec Then
         Resume AddSec
      Else
         Resume AddNew
      End If
   Else
      MsgBox Err.Description, vbInformation
      Resume CDJJobCount_Exit
   End If
   Resume

Banana, I don't see how I can use break on all errors to find this error because it halts the code as soon as it hits the error 5 and I don't see a way to resume execution at that point. It hits a ton of error 5's before it ever gets to the other error.

Thanks.
 
An error 5 is "You don't have permission to connect to this" (paraphrased) so I'm wondering why all of the error 5's are happening and if you don't have permission to connect to that object why is it there to begin with? I think that would be an important thing to know.
 
Quite puzzling... There are 6 separate occurrences of the line of code that generates error #5. In all cases, the error is handled and execution is resumed. If I remove the error handler and instead duplicate that code in each of those 6 locations, I get an error about a key value already being assigned.

This sub uses a class module and a collection and those are 2 things that I have no experience with so I doubt I would get anywhere trying to decipher it.

I did manage to dig deep and find the source of the other error I was trying to fix so I guess I'll just leave the rest of the code as is.


Thanks again for your help.
 

Users who are viewing this thread

Back
Top Bottom