Results 1 to 5 of 5
  1. #1
    gar is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Nov 2011
    Posts
    39

    Undefined user-defined data type

    I created a blank database, accepting the default name of "Database1". I imported into it some objects, including a VBA module, from an existing database. When I ran one of the VBA procedures I got the error message: "Compile error: User-defined type not defined". The debugger indicated that the offending type was "Database" in the context: "Dim db As Database". I have never created a user-defined data type so I retyped "Dim db As" to confirm that Database was included in the drop-down list of system defined types. To my surprise Database wasn't included in the list but "Database1" was! Can anyone explain what's going on?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    8,947
    you dont really need the DIM db as database. so either:

    remove dim db as database, then replace the db with Currentdb....
    like:
    db.openrecordset
    with currentdb.openrecordset

    OR

    load in the REFERENCE to allow DIM db as database,
    in vbe menu (alt-F11) , menu: tools , references,
    check the box: Microsoft DAO xx.xx Object LIbrary.

    either will work.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,408
    I use
    Code:
    Dim d As DAO.Database
    If I get the error "Compile error: User-defined type not defined", I open the IDE and click on TOOLS/References.
    I find "Microsoft Office xx.0 Object Library" and check it. (for A2010, xx is 14)

    In A2010, trying to set a reference to "Microsoft DAO xx.xx Object LIbrary" results in an error. Hence the "Microsoft Office" reference.....
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  4. #4
    gar is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Nov 2011
    Posts
    39
    Quote Originally Posted by ranman256 View Post
    you dont really need the DIM db as database. so either:

    remove dim db as database, then replace the db with Currentdb....
    like:
    db.openrecordset
    with currentdb.openrecordset

    OR

    load in the REFERENCE to allow DIM db as database,
    in vbe menu (alt-F11) , menu: tools , references,
    check the box: Microsoft DAO xx.xx Object LIbrary.

    either will work.
    I tried option two and on checking the DAO box I received the error message: "Name conflicts with existing module, project or object library." There was no indication of the "Name" to which the message referred.

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I have found that too, for some reason they have removed the reference to the DAO library after 2010. As suggested, remove the DIM and use CurrentDB instead, changing all references to "db" to "CurrentDB".

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2017, 09:09 AM
  2. DAO ERROR - User Defined type not defined
    By adamtate94 in forum Programming
    Replies: 2
    Last Post: 09-08-2016, 05:42 AM
  3. mydb - User-defined type not defined
    By adams77 in forum Forms
    Replies: 4
    Last Post: 07-22-2015, 08:43 AM
  4. Replies: 3
    Last Post: 11-12-2013, 04:13 PM
  5. user-defined type not defined
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 05-09-2013, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums