Solved

Object variable or With block variable not set

Posted on 2002-07-11
9
241 Views
Last Modified: 2010-05-18
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?
0
Comment
Question by:GivenRandy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 7146111
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
 
LVL 9

Author Comment

by:GivenRandy
ID: 7146142
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
 
LVL 9

Author Comment

by:GivenRandy
ID: 7146143
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7146161
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
 
LVL 2

Accepted Solution

by:
damienm earned 100 total points
ID: 7146181
Or when you start getting the error messages press control and break at the same time.
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 7146464
Cntr-Brk does it. Now I just have to remember that for next time! Thanks!
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 7146474
I will also put half-value points for angelIII and mdougan (check in a few minutes).
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7147239
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
 
LVL 9

Author Comment

by:GivenRandy
ID: 7147274
LOL. Yeah, sometimes I forget the most basic things -- especially when the pressure is on.  :)  Fortunately, that doesn't happen TOO often.  ;)
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 61
Protecting vb6 & .Net code Obfuscation 18 184
Child Form in front 4 57
Excel Userform to write back to spreadsheet in a different font or colour 8 12
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question