PRB: Object Variable Not Set Error If Object Not InstantiatedLast reviewed: October 30, 1995Article ID: Q129836 |
The information in this article applies to:
SYMPTOMSReferencing an object that has not been instantiated results in this error:
"Object variable or With block variable not Set" (Err = 91) CAUSEIf you declare an object as in this example:
Dim MyForm as Form1you have allocated a reference to the object (similar to a pointer in the C programming language), but you have not allocated or instantiated the object itself. Therefore, when the object is referenced in code as in this example:
MyForm.Print "Hello World!"the error message "Object variable or With block not Set" is generated.
RESOLUTIONThe following three code examples demonstrate how to declare and use an object variable (MyForm in this case) correctly:
Code Sample OneDim MyForm as Form1 Set MyForm = New Form1 ' Where the object type is the same as the object type used in the ' declaration.MyForm.Print "Hello World!"
Code Sample TwoDim MyForm as New Form1 MyForm.Print "Hello World!"
Code Sample ThreeDim MyForm as Form1 Dim MyForm1 as New Form1 Set MyForm= MyForm1 MyForm.Print "Hello World!"
|
Additional reference words: 4.00 vb4win vb4all
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |