1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Dseefine DB as Database error

Discussion in 'Business Applications' started by tomlock2, Dec 6, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. tomlock2

    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!
     
  2. OBP

    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.
     
  3. tomlock2

    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?



     
  4. Rockn

    Rockn

    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
     
  5. tomlock2

    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.
     
  6. OBP

    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?
     
  7. tomlock2

    tomlock2 Thread Starter

    Joined:
    Nov 20, 2011
    Messages:
    49
    Not sure what you mean 'scroll down and see what version is actually listed'?
     
  8. Sponsor

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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1029943

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice