Database not a recognized data type

G

Guest

I am using Access 2003. When I use Dim db as Database, I get a Compile Error
message telling me that the data type is not defined. How do I get around
this problem?

I am trying to open a recordset and I am using the following code:
Dim db As Database
Dim rstTemp As Recordset

Set db = CurrentDb()
Set rstTemp = db.OpenRecordset("WRTEST")

I tried not declaring db and using Set rstTemp =
CurrentDB.OpenRecordset("WRTEST") instead but that does not work....

Any ideas???
 
J

Jeff Conrad

in message:
I am using Access 2003. When I use Dim db as Database, I get a Compile Error
message telling me that the data type is not defined. How do I get around
this problem?

I am trying to open a recordset and I am using the following code:
Dim db As Database
Dim rstTemp As Recordset

Set db = CurrentDb()
Set rstTemp = db.OpenRecordset("WRTEST")

I tried not declaring db and using Set rstTemp =
CurrentDB.OpenRecordset("WRTEST") instead but that does not work....

That's odd.
The code you posted is most definitely DAO code and by default
Access 2003 does set a reference to the DAO object library. Did
you by chance remove this reference? We need to open up the
References dialog box to check. Follow these instructions:

To fix the References problem follow these steps:
- Open any module in Design view.
- On the Tools menu, click References.
- Scroll down to you get to Microsoft DAO 3.xx and check it.
- If you're using Access 97 that should be DAO 3.51 Object Library.
- If you're using Access 2000, 2002, or 2003 that should be DAO 3.6 Object Library.
- Close the References box again.
- Now re-compile again. Debug--Compile.
- Hopefully you should not see any more compile errors.

As good practice it may also be better to use this:

Dim db As DAO.Database
Dim rstTemp As DAO.Recordset

....rather than:

Dim db As Database
Dim rstTemp As Recordset

This helps to avoid confusion for Access (but you still have to manually
set a reference to DAO for 2000 and 2002) if you have a reference set
to both the DAO and ADO object libraries.

I hope that helps,
 
G

Guest

Thank you so much. DAO was not selected in the Object Library. Once I
selected it everything was fine. Not sure how it got deselected... It may be
because I have 2 versions of Access (Access 97 and 2003) on my PC!
 
J

Jeff Conrad

in message:
Thank you so much. DAO was not selected in the Object Library. Once I
selected it everything was fine. Not sure how it got deselected... It may be
because I have 2 versions of Access (Access 97 and 2003) on my PC!

You're very welcome, I'm glad I could help fix the problem.
Good luck with your project.
 

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

Top