PRB: Object Variable Not Set When Referencing Data ControlLast reviewed: November 17, 1995Article ID: Q110618 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 3.0
SYMPTOMSIf a Data control references the Recordset property in the Form_Load event or anytime BEFORE the Form_Activate event, you will receive the following error message (Error#91):
Object Variable Not SetYou can also receive the "Object variable not set" error with the Data control, without necessarily being in a Form-Load event, if you assign the Recordsource property to a table name without quotation marks and then do an addnew. For example:
data1.recordsource = tablename 'where tablename is neither a string 'variable containing a valid table name, nor a quoted string. data1.refresh data1.recordset.addnew 'Gives "Object variable not set." CAUSEThe RecordSet property of a Data Control is not resolved until after the form has been loaded -- that is, after the Form_Load event. This means that you cannot issue any method such as MoveNext or FindNext of the Data Control that uses its record set (its internal Dynaset).
RESOLUTIONTo prevent the error, force the creation of the internal dynaset in the data control by issuing the Refresh method:
Data1.RefreshThis will validate the RecordSet property allowing you to use methods that require this.
STATUSThis behaviour is by design.
MORE INFORMATIONNOTE: This problem also occurs in Visual Basic for Applications when you define an object and don't use it. In the General Declarations section of your the code, where the variable is dimmed as an Object, as in the following:
Dim X as Objectcomment out or delete this. Also, if "X" is set to something, for example
Set X = "John Doe"and is not used later in the procedure, then comment out or delete this line as well.
Steps to Reproduce Behavior
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |