Solved

Object variable or With block variable not set

Posted on 2002-07-11
9
239 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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