Solved

Object variable or With block variable not set

Posted on 2002-07-11
9
236 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

895 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

15 Experts available now in Live!

Get 1:1 Help Now