Results 1 to 6 of 6
  1. #1
    John53T is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    3

    Copying VBA from one Database to another


    Hi
    I have an existing database that has a VBA to select criteria based on a list box. This works quite well, but well I duplicated the database and took away some whistles and bells, the VBA did not work but rather came back with: Compile error: User-defined type not defined - Dim Q as QueryDef.
    I am not understanding this as it is duplicated from the original database that is working.
    Any Help?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Sometimes it is a false error.
    in the VBE (ctl-G) menu,tools,references,
    if any checked items say MISSING , it can cause false vb errors.

  3. #3
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by John53T View Post
    Hi
    I have an existing database that has a VBA to select criteria based on a list box. This works quite well, but well I duplicated the database and took away some whistles and bells, the VBA did not work but rather came back with: Compile error: User-defined type not defined - Dim Q as QueryDef.
    I am not understanding this as it is duplicated from the original database that is working.
    Any Help?

    Did you also duplicate all the References in the same order?

    To check the references, in the VBA Editor go to Tool > References.

    I would recommend being explicit with your code like the following

    Code:
    Dim Q as DAO.QueryDef

  4. #4
    John53T is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    3
    Hi Ranman256,

    Thanks for that, but there are no checked boxes with a missing text.

  5. #5
    John53T is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    3
    Hi HiTechCoach,

    I compared the two references and noted that the Microsoft Internet Controls and Microsoft Office 16 Access Database Object Library were not checked. Checking them, then gave me the results I needed. Thank you all so much.

  6. #6
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by John53T View Post
    Hi HiTechCoach,

    I compared the two references and noted that the Microsoft Internet Controls and Microsoft Office 16 Access Database Object Library were not checked. Checking them, then gave me the results I needed. Thank you all so much.
    You're welcome. Glad we could assist.

    TIP: Copying or importing VBA between database does not include any required references. You will not see required references checked or marked as MISSING. A good programming practice is to put comments in the code that specify any required reference(s) that needs to be set. It is good idea to read the comment inbt he code.

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

Similar Threads

  1. Copying table data to different database
    By m450n86 in forum Programming
    Replies: 1
    Last Post: 04-11-2017, 01:46 AM
  2. Replies: 16
    Last Post: 09-10-2016, 12:39 AM
  3. Replies: 5
    Last Post: 02-08-2014, 03:06 PM
  4. Copying of a Form
    By Mahendra1000 in forum Access
    Replies: 2
    Last Post: 01-28-2014, 04:21 AM
  5. Keep From Copying Database
    By jmyersnc in forum Programming
    Replies: 2
    Last Post: 02-07-2010, 07:44 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