Tech Support Guy banner
Status
Not open for further replies.

Dseefine DB as Database error

3K views 6 replies 3 participants last post by  tomlock2 
#1 ·
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!
 
#2 ·
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.
 
#3 ·
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.
 
#5 ·
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.
 
#6 ·
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?
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top