Microsoft KB Archive/288276

= Access quits when binding a form to an ADO recordset using Jet in Access 2002 =

Article ID: 288276

Article Last Modified on 8/13/2004

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



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 = &quot;Customers&quot; .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 = &quot;Customers&quot; .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.



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.

 Open the sample database Northwind.mdb. Open the Customers form in Design view. On the View menu, click Code to view the module of the form. On the Tools menu, click References. Click to select the Microsoft ActiveX Data Objects 2.5 Library check box, and then click OK to close the References dialog box.</li>  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 = &quot;Customers&quot; .CursorLocation = adUseServer .CursorType = adOpenKeyset .LockType = adLockOptimistic .Open Options:=adCmdTableDirect End With Set Me.Recordset = rs End Sub </li> On the File menu, click Close and return to Microsoft Access.</li> On the File menu, click Save.</li> On the View menu, click Form View.</li></ol>

Note that you receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.

<div class="references_section">