OpenRecord method

  • Thread starter Thread starter George
  • Start date Start date
G

George

I get a "type mismatch" error with the following code:

dim rst as recordset
set rst = DBEngine.Workspaces(0).Databases
(0).OpenRecordset("tblName") - all on one line

I have tried currentdb in place of DBEngine.Workspaces
(0).Databases(0) and setting up a string containing a
select statement. All variations produce the same
error. Can anyone help?
 
I get a "type mismatch" error with the following code:
dim rst as recordset
set rst = DBEngine.Workspaces(0).Databases
(0).OpenRecordset("tblName") - all on one line

I have tried currentdb in place of DBEngine.Workspaces
(0).Databases(0) and setting up a string containing a
select statement. All variations produce the same
error. Can anyone help?

You need to make sure that you have a reference to the appropriate DAO Object
Library for your version of Access and, if using Access 2000, or later, you
should disambiguate your objects as follows:

Dim rst as DAO.Recordset

You could also remove the reference to the ActiveX Data Objects library if you
won't be using it.

**
To determine which DAO library is appropriate for the applicable version of
Access, see the following MS KB article:

ACC2002: References That You Must Set When You Work with Microsoft Access
http://support.microsoft.com/default.aspx?kbid=283115

Scroll down through that page until you reach the section entitled "Setting a
Reference to DAO for different versions of Microsoft Access".
 
I get a "type mismatch" error with the following code:

dim rst as recordset
set rst = DBEngine.Workspaces(0).Databases
(0).OpenRecordset("tblName") - all on one line

I have tried currentdb in place of DBEngine.Workspaces
(0).Databases(0) and setting up a string containing a
select statement. All variations produce the same
error. Can anyone help?

Open the VBA editor and select Tools... References from the menu. It
appears that you are using A2000 or later and that it's defaulting to
using the newer ADO data model; your code use the older DAO objects.

Scroll down and find the reference for "Microsoft DAO x.xx Object
Library", latest version, and check it. You may also want to uncheck
the ActiveX Data Objects reference if you aren't intentionally using
ADO; if you leave both checked, it's safest to use

Dim rst As DAO.Recordset

since both DAO and ADO have Recordset objects... but they are
*different* objects.
 
Back
Top