Dseefine DB as Database error

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

tomlock2

Thread Starter
Joined
Nov 20, 2011
Messages
49
I just created a new database in ACCESS 2010. I then copied over some objects from a previous database. On one of the FORMS objects I copied over there is VBA code. When I try to open that form I get the following error ---

Compile Error
Expected user-defined type, not project

The error occurs on the following statement--
DIM DB as Database


This seems odd to me since I use the same statement in another ACCESS 2010 database and it works fine.

I am confused. Please help!
 

OBP

Joined
Mar 8, 2005
Messages
19,895
I do not know Access 2010, but I can suggest a way around the problem, you can use late binding instead of early binding.
Use
Dim DB as Object
and then use the Set statement to set it to the database.

The other thing you can try is ensure that the Library References in the 2 databases are the same.
 

tomlock2

Thread Starter
Joined
Nov 20, 2011
Messages
49
I suspect the Library References is the problem but I don;t know where they can be set/chged?



I do not know Access 2010, but I can suggest a way around the problem, you can use late binding instead of early binding.
Use
Dim DB as Object
and then use the Set statement to set it to the database.

The other thing you can try is ensure that the Library References in the 2 databases are the same.
 
Joined
Jul 29, 2001
Messages
21,334
You have to go into the VB editor and go to tools > references. It will show you what is missing
 

tomlock2

Thread Starter
Joined
Nov 20, 2011
Messages
49
LIbQUOTE=Rockn;8176697]You have to go into the VB editor and go to tools > references. It will show you what is missing[/QUOTE]

When I go to the Tools References in the VBA editor I see a list of many names with check boxes the 1st 5 of which are checked. I then scroll down to the unchecked one Miscrosoft DAO 3.6 Object Library and select it and check OK. I then get the error message --- 'Name conflicts with existing module, project or object library'.

However if I change all of my code that is now = "Dim DB as Database" or "Dim rec as Recordset" to "Dim DB as DAO.Database" and "Dim rec as DAO.Recordset the code works.

Interestingly I created a database a couple of days ago with VBA code w/o the DAO qualifier on the Dim statements and it works fine. I checked it Tools References in the VBA editor and they appear the same as the database I had problems with required the DAO qualifier to work.

This gives me a bit of an uneasy feeling.
 

OBP

Joined
Mar 8, 2005
Messages
19,895
It could be that the database "project" which contains the VBA code needed Compiling in the new version.
The DAO 3.6 Object is probably not what Access 2010 uses did you scroll down and see what version is actually listed?
 

tomlock2

Thread Starter
Joined
Nov 20, 2011
Messages
49
It could be that the database "project" which contains the VBA code needed Compiling in the new version.
The DAO 3.6 Object is probably not what Access 2010 uses did you scroll down and see what version is actually listed?
Not sure what you mean 'scroll down and see what version is actually listed'?
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top