Access quits when binding a form to an ADO recordset using Jet in Access 2002 (288276)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q288276
Advanced: Requires expert coding, interoperability, and multiuser skills.

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

SYMPTOMS

When you open a form that is bound to an ActiveX Data Objects (ADO) recordset, you receive the following error message, and then Microsoft Access quits:
Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience.
When you view the details in the error report, the report says that Microsoft Access caused an error in Msado15.dll.

CAUSE

This problem occurs under the following conditions:
  • You have Microsoft Data Access Components (MDAC) 2.5 installed on your computer.
  • You are binding the Recordset property of a form to an ADO recordset that is opened with the Microsoft Jet 4.0 OLE DB provider.
  • The ADO recordset is using a server-side cursor.
  • You are using the adCmdTableDirect option to open the ADO recordset.

RESOLUTION

There are two possible resolutions for this problem.

Use the Microsoft Access 10.0 OLE DB Service Provider

You can work around this problem by using the Microsoft Access 10.0 OLE DB service provider. Set the ActiveConnection property of the ADO recordset to an ADO connection that uses the Microsoft Access 10.0 OLE DB service provider along with the Microsoft Jet 4.0 OLE DB data provider. In Microsoft Access, the CurrentProject.AccessConnection property returns an ADO connection to the currently open database using the Microsoft Access 10.0 OLE DB service provider. For example, you can open the recordset by using code similar to the following:
Private Sub Form_Open(Cancel As Integer)
   Dim cn As ADODB.Connection
   Dim rs As ADODB.Recordset

   Set cn = CurrentProject.AccessConnection
   Set rs = New ADODB.Recordset
   With rs
      .ActiveConnection = cn
      .Source = "Customers"
      .CursorLocation = adUseServer
      .CursorType = adOpenKeyset
      .LockType = adLockOptimistic
      .Open Options:=adCmdTableDirect
   End With
   Set Me.Recordset = rs
End Sub
				

Use a Client-Side Cursor

You can work around this problem by using the Microsoft Jet 4.0 OLE DB provider, as long as you open the ADO recordset as a client-side cursor. To open the ADO recordset as a client-side cursor, set the CursorLocation property of the recordset to the adUseClient constant. For example, you can open the recordset by using code similar to the following:
Private Sub Form_Open(Cancel As Integer)
   Dim cn As ADODB.Connection
   Dim rs As ADODB.Recordset

   Set cn = CurrentProject.Connection
   Set rs = New ADODB.Recordset
   With rs
      .ActiveConnection = cn
      .Source = "Customers"
      .CursorLocation = adUseClient
      .CursorType = adOpenKeyset
      .LockType = adLockOptimistic
      .Open Options:=adCmdTableDirect
   End With
   Set Me.Recordset = rs
End Sub
				

STATUS

Microsoft has confirmed that this is a problem in Microsoft Access.

MORE INFORMATION

Steps to Reproduce the Behavior

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.
  2. Open the Customers form in Design view.
  3. On the View menu, click Code to view the module of the form.
  4. On the Tools menu, click References.
  5. Click to select the Microsoft ActiveX Data Objects 2.5 Library check box, and then click OK to close the References dialog box.
  6. Add the following event procedure to the module of the form:
    Private Sub Form_Open(Cancel As Integer)
       Dim cn As ADODB.Connection
       Dim rs As ADODB.Recordset
    
       Set cn = CurrentProject.Connection
       Set rs = New ADODB.Recordset
       With rs
          .ActiveConnection = cn
          .Source = "Customers"
          .CursorLocation = adUseServer
          .CursorType = adOpenKeyset
          .LockType = adLockOptimistic
          .Open Options:=adCmdTableDirect
       End With
       Set Me.Recordset = rs
    End Sub
    					
  7. On the File menu, click Close and return to Microsoft Access.
  8. On the File menu, click Save.
  9. On the View menu, click Form View.
Note that you receive the error message that is mentioned in the "Symptoms" section of this article.

REFERENCES

For additional information about binding forms to ADO recordsets, click the following article number to view the article in the Microsoft Knowledge Base:

281998 How to bind Microsoft Access forms to ADO recordsets

For additional information about the difference between the Connection and the AccessConnection properties, click the following article number to view the article in the Microsoft Knowledge Base:

281784 Difference Between Connection and AccessConnection Properties


Modification Type:MajorLast Reviewed:8/13/2004
Keywords:kbdta kbnofix KB288276