Compile Error

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I am getting a Compile Error: User-Defines Type Not Defined. On the Dim db As
Database.

However I have it defined as below.

Dim db As Database

Set db = CurrentDb()

Why is this happening?
 
G

Granny Spitz via AccessMonster.com

mattc66 said:
I am getting a Compile Error: User-Defines Type Not Defined. On the Dim db As
Database.

Open the VB code window, Tools | References, then scroll down and check the
Microsoft DAO 3.6 Object Library, hit OK and compile the code. (Ok, now I'm
off for the afternoon. Why aren't you googling for those many, many code
samples for your other problem instead of posting a new question?!)
 
M

mattc66 via AccessMonster.com

That stopped that error message. Now I am getting Run-Time Error '13': Type
Mismatch.

Set rs1 = db.OpenRecordset("Table1")

Any Idea why I'd get that when I try and OpenRecordset?
 
J

John Vinson

That stopped that error message. Now I am getting Run-Time Error '13': Type
Mismatch.

Set rs1 = db.OpenRecordset("Table1")

Any Idea why I'd get that when I try and OpenRecordset?

ADOX and DAO both have recordset objects - DIFFERENT recordset
objects!

Be sure you

Dim rs1 As DAO.Recordset

and/or remove the Access Data Objects reference if you're not using
ADO.

John W. Vinson[MVP]
 
M

mattc66 via AccessMonster.com

That fixed it.

John said:
ADOX and DAO both have recordset objects - DIFFERENT recordset
objects!

Be sure you

Dim rs1 As DAO.Recordset

and/or remove the Access Data Objects reference if you're not using
ADO.

John W. Vinson[MVP]
 
G

Granny Spitz via AccessMonster.com

mattc66 said:
Any Idea why I'd get that when I try and OpenRecordset?

It means you have the ADO library in your references too, and both the ADO
and DAO libraries have a Recordset object. The first library on the list is
used (takes precedence) unless you disambiguate the variable declaration.
Access is trying to apply an ADODB.Recordset object to a DAO.Recordset
reference (db.OpenRecordset), so you get a data type mismatch. If you aren't
using code that needs the ADO library, you can remove it from your list of
references. If you are, you need to explicitly declare which library you're
using for the Recordset object:

Dim rs1 As DAO.Recordset
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top