Microsoft KB Archive/287485

= &quot;Object variable or With block variable not set&quot; error message when you use Delete or UpdateBatch methods =

Article ID: 287485

Article Last Modified on 1/31/2007

-

APPLIES TO


 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q287485



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SYMPTOMS
When you use code that performs Delete and UpdateBatch methods based on the Forms collection, you receive the following error message:

Microsoft Visual Basic

Run-time error '91':

Object variable or With block variable not set



RESOLUTION
Make sure the Recordset object is not based on the form's recordset if you plan to use the Delete or UpdateBatch methods. For an example, see the following code: Sub Test

Dim rs As New ADODB.Recordset rs.Open &quot;SELECT * FROM TableX&quot;, CurrentProject.Connection, _ adOpenKeyset, adLockOptimistic rs.Delete rs.UpdateBatch

End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Open the sample project NorthwindCS.adp connected to SQL Server 2000.  Create the following new table:   Table: TableX Column Name: ID  Data Type: int Allow Nulls: not checked Identity: Yes

Column Name: Field1 Data Type: char

Table Properties: TableX PrimaryKey: ID                    Save the table as TableX . Open the TableX table in Datasheet view. Enter five rows of data in the Field1 field.</li> Create a new, unbound form.</li> Switch to Form view.</li> Press ALT+F11 to open the Visual Basic Editor.</li>  Insert a new module, and then type or paste the following code: Sub Test

Dim rs As New ADODB.Recordset rs.Open &quot;SELECT * FROM TableX&quot;, CurrentProject.Connection, _ adOpenKeyset, adLockOptimistic Set Forms(0).Recordset = rs  Forms(0).Recordset.Delete Forms(0).Recordset.UpdateBatch

End Sub </li> Place the mouse pointer anywhere in the procedure, and then press F5. Note that you receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

Additional query words: pra ACC2002

Keywords: kbfunctions kbvba kbprogramming kbbug kberrmsg kbpending KB287485

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.