Why doesn't this VB code compile?

P

phobos

Hi,

Here is the code:


Option Compare Database

Sub exaObjectVar()

Dim dbLib As DATABASE
Dim rsPeople As Recordset

Set dbLib = CurrentDb
Set rsPeople = dbLib.OpenRecordset("People")
MsgBox "People record count: " & rsPeople.RecordCount

End Sub


When I try to compile it I get the following error message:


Compile error: User-defined type not defined


The offending line is "Dim dbLib As DATABASE" but I don't get it, because
the way I see it dbLib gets defined on the "Set dbLib = CurrentDb" line.

This code is a module in a database called db1, which has one table called
People. I suspect its something quite simple, but I'm very new to Access
and VB and any help would be appreciated. I'm using Access 2000.

TIA
 
P

phobos

Rick Brandt wrote [06 Jul 2003] :

Your code would compile in Access 97. Access 2000 does not
use the DAO library by default and Database is a DAO object.
Open a code module and use Tools- References to remove the
ADO reference and replace with the DAO reference. Or if you
want to use both you'll need to get in the habit of
explicity identifying objects that exist in both libraries.
Instead of Recordset you would use DAO.Recordset for
example.


Nice work!

Thanks a lot.
 
G

Guest

You need to update your references. In VB choose
Tools/References. Find Microsoft DAO 3.6 Object Library
and check the box. Then move it up in priority as high as
it will go. That should fix your problem.
 

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