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
Solved

"91 Object Variable or Block Width Variable Not Set" Error

Posted on 2001-09-18
3
292 Views
Last Modified: 2011-10-03
I have a DLL that is being loaded and throws this error at runtime: "91 Object Variable or Block Width Variable Not Set".  What does it mean?  How can I solve it?  It sounds like a NullPointerException.  
0
Comment
Question by:hotwheels
3 Comments
 
LVL 1

Accepted Solution

by:
ripnasty earned 100 total points
ID: 6490803
That error usually means that you make reference to an object somewhere in your startup code that hasn't been set to anything.

For example, if you declare a recordset (rsTest) but don't set it to anything and make reference to it, you will get this error

i.e.

Dim rsTest as Recordset
If rsTest.EOF then
.
.
.
End If

The rsTest.EOF will produce an Object Variable Not Set error because it hasn't been set to anything.  Trap through your startup code and debug will tell you whether your object variables have been set or not.

Hope this helps!
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6490950
ripnasty is correct and forgot to show the usual cure:

Dim rsTest as Recordset

' add this line
set rsTest = new Recordset

If rsTest.EOF then


--
In the case of a class, do the same thing:

Dim clsMyOwnClass as ClassName

Set clsMyOwnClass = New ClassName

clsMyOwnClass.MyProperty = MyValue

...
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6492080
Yes as the others have said this is due to declaring an instance of an object and not instanciating it.

Examples:

'Object declaration
Dim objMyObject as MyObject

objMyObject.MyProperty = 1
or
objMyObject.DoSomething

This will give this error.
The correct syntax is.

Dim objMyobject as MyObject
Set objMyObject = new MyObject
or
Dim objMyobject
Set objMyObject = CreateObject("MyObject")
or
Dim objMyobject
Set objMyObject = GetObject(,"MyObject")

The following will also cause this error.


Dim objMyObject as MyObject 'Declaration
Set objMyObject = new MyObject 'Instance

myObject.MyProperty = 1
myObject.DoSomething

Set MyObject = Nothing 'Object destroyed

myObject.MyProperty = 1

This will also give the error.

So have a good look at the code an make sure objects are being created properly and not being used after they have been destroyed.  

This is the same as the NullPointerException in Java.

Vin.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

856 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