ACC2000: Can't Set Form Recordset to Disconnected Recordset

ID: Q230737


The information in this article applies to:

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access project (.adp).


SYMPTOMS

When you try to assign an ActiveX Data Objects (ADO) Recordset object to a form, you may receive the following error message:

The object you entered is not a valid Recordset property.


CAUSE

You assigned a disconnected ADO Recordset object to the Recordset property of the form.


RESOLUTION

Set the ActiveConnection property of the ADO recordset to a valid ADO Connection object before assigning it to the form.


MORE INFORMATION

ADO allows you to create a recordset, and then to disconnect it from its source. In a client/server environment, this allows you to update the recordset on the client without maintaining a constant connection to the server. Later, your changes are batch updated to the server. Even though ADO allows you to disconnect a recordset from its source and manipulate it on the client without a connection, Microsoft Access forms bound to Recordset objects require a valid ADO Connection object.

Steps to Reproduce Behavior

CAUTION: Following the steps in this example will modify the sample Access project NorthwindCS.adp. You may want to back up the NorthwindCS.adp file and perform these steps on a copy of the project.

  1. Open the sample Access project NorthwindCS.adp.


  2. Open the Customers form in Design view.


  3. Clear the RecordSource property of the form so that the form is no longer bound.


  4. On the View menu, click Code.


  5. Add the following event procedure to the module of the form:


  6. 
    Private Sub Form_Open(Cancel As Integer)
        Dim rs As ADODB.Recordset
            
        'Create a new ADO recordset, and disconnect it
        Set rs = New ADODB.Recordset
        With rs
            .ActiveConnection = CurrentProject.Connection
            .CursorType = adOpenKeyset
            .LockType = adLockOptimistic
            .Source = "SELECT * FROM Customers"
            .Open
            .ActiveConnection = Nothing
        End With
        Set Me.Recordset = rs
    End Sub 
  7. Switch from the Visual Basic Editor to Microsoft Access.


  8. Save the Customers form and close it.


  9. Open the Customers form in Form view from the Database window. Note that you receive the following error when setting the form Recordset property to the disconnected recordset:


  10. The object you entered is not a valid Recordset property.


REFERENCES

For additional information about using disconnected recordsets with ADO, please see the following articles in the Microsoft Knowledge Base:

Q190717 Disconnected Recordsets with ADO or RDS
Q184397 Getting ADO Disconnected Recordsets in VBA/C++/Java
For more information about using the form Recordset property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "Form Recordset Property" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: prb


Keywords          : kberrmsg kbdta AccessCS 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: July 6, 1999