PRB: Object Variable Not Set When Referencing Data Control (110618)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 2.0
- Microsoft Visual Basic Standard Edition for Windows 3.0
- Microsoft Visual Basic Professional Edition for Windows 2.0
- Microsoft Visual Basic Professional Edition for Windows 3.0
This article was previously published under Q110618 SYMPTOMS
If 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 Set
You 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."
CAUSE
The 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).
RESOLUTION
To prevent the error, force the creation of the internal dynaset in the
data control by issuing the Refresh method:
Data1.Refresh
This will validate the RecordSet property allowing you to use methods that
require this.
STATUS
This behaviour is by design.
Modification Type: | Major | Last Reviewed: | 12/9/2003 |
---|
Keywords: | kbprb KB110618 |
---|
|