Object variable or With block variable not set

I am getting an "Object variable or With block variable not set" error. However, it does not allow break to debug -- it just keeps giving the error message box thousands of times. The program is large. How can I pinpoint what is causing the error without putting breakpoints all over the place?
LVL 9
GivenRandyAsked:
Who is Participating?
 
damienmCommented:
Or when you start getting the error messages press control and break at the same time.
0
 
mdouganCommented:
When you start your program, start it by clicking F8 instead of F5 or the run button.  This will single step to the first instruction.  Then, just start hitting F8 until you run into the error.  It may be time consuming, but eventually you will hit the code.

You can do a quick scan ahead of time for all object variables, any variable where you use the Set statement.  Then (and this is a good practice anyway), in every procedure where you reference one of these object variables, you should always have a condition that checks to see if the variable is initialized by having some code like:

If Not oCustomer Is Nothing then
   oCustomer.GetBalance
Else
   msgbox "Error getting Customer balance"
End if

You should also make sure that you have error handlers in every procedure.  You could also try going to the Tools|Options menu, then the General tab, and click Break on all errors.
0
 
GivenRandyAuthor Commented:
I will the last one and other ideas.

F8: I should mention that it start and runs for several seconds (many, many F8 steps) before any errors.

Compiles: The modules use Option Explicit and it compiles (builds) without errors.

Nothing: Much of this is legacy code and a lot of it -- will be hard to check each instance for proper checks of Nothing.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
GivenRandyAuthor Commented:
I will the last one and other ideas.

F8: I should mention that it start and runs for several seconds (many, many F8 steps) before any errors.

Compiles: The modules use Option Explicit and it compiles (builds) without errors.

Nothing: Much of this is legacy code and a lot of it -- will be hard to check each instance for proper checks of Nothing.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Check the BREAK options, set it to "Break on all errors", you will get to the line that hits the error.
Right-click in the code window, choose Toggle, and choose the above.
CHeers
0
 
GivenRandyAuthor Commented:
Cntr-Brk does it. Now I just have to remember that for next time! Thanks!
0
 
GivenRandyAuthor Commented:
I will also put half-value points for angelIII and mdougan (check in a few minutes).
0
 
mdouganCommented:
Yikes... when you said that it doesn't allow you to break on the error to debug, I thought you meant that you WERE doing the ctrl+break .... <g>
0
 
GivenRandyAuthor Commented:
LOL. Yeah, sometimes I forget the most basic things -- especially when the pressure is on.  :)  Fortunately, that doesn't happen TOO often.  ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.