If you must reference and use both DAO and ADO Recordset objects, dimension the objects explicitly as follows:
Dim adoRS As ADODB.Recordset
Dim daoRS As DAO.Recordset
Steps to reproduce the behavior
- Start Visual Studio. The New Project dialog box appears.
- Click Open. The Form1 form appears.
- Right-click the Form1 form, and then click View Code. The Project1 - Form1 (Code) window appears.
- Paste the following code in the Project1 code page:
Dim dbs AS Database
Dim rs AS Recordset ' When you press the spacebar after "AS," the
' list box includes multiple Recordset entries.
' Pick any Recordset item, or type "Recordset."
Private Sub Form_Load()
Set rs=dbs.OpenRecordset(source) ' The error occurs when this line
' of code executes.
- On the Project menu, click References. The References - Project1 dialog box appears.
- Click Microsoft DAO 3.x Object Library, click Microsoft ActiveX Data Objects 2.x Library, and then click OK.
Note Make sure that the ADO library has the higher priority in the References dialog box list above the DAO library.
- On the Run menu, click Start to run the program. You may receive the error message that is mentioned in the "Symptoms" section.