Solved

Object variable or With block variable not set

Posted on 2002-07-11
9
235 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
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
 
LVL 142

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now