+ Reply to Thread
Results 1 to 3 of 3

VBA to open Access DB

  1. #1
    Registered User
    Join Date
    08-01-2016
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    VBA to open Access DB

    I am trying to open an Access Database from a button within Excel.

    However when I attempt to run it I get the following error:
    Compile Error
    User-defined type not definded

    on - db As Access.Application


    The code I am using is as follows:
    ------------------------------------
    Dim db As Access.Application

    Public Sub OpenDB()

    Set db = New Access.Application
    db.OpenCurrentDatabase "C:\Data\Report.accdb"
    db.Application.Visible = True

    End Sub
    Last edited by Moedeb27; 08-24-2016 at 07:21 PM.

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Wink Re: VBA to open Access DB

    You need to define the reference before automating Access. Do this from the VB Editor / tools/ References and tick the reference to Microsoft Access 16.0 Object Library. I've edited this post to give examples of opening the full database and opening it using DAO, which gives you control of the tables and queries as record sets, but not anything else.

    DAO and early binding
    Please Login or Register  to view this content.
    If you are going to share this with users of older versions of Office, you will need to use late binding instead. You do not need to set a reference in the VB Editor with late binding. This example opens the application rather than the tables and queries.
    Please Login or Register  to view this content.
    Last edited by Neil_; 08-23-2016 at 04:43 AM.
    Frob first, tweak later

  3. #3
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: VBA to open Access DB

    And finally, Using ADDOB. You need to set a reference to "Microsoft ActiveX Data Objects Recordset 2.0 Library" to enable early binding.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Open PDF from Combo Box in Access
    By acmagyar in forum Access Tables & Databases
    Replies: 4
    Last Post: 04-25-2014, 08:28 AM
  2. [SOLVED] Open access from excel
    By sebastienkanj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2013, 05:04 AM
  3. Open MS-ACCESS and Run Saved Imports in Access
    By Manikanta546 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2013, 08:05 AM
  4. Not able to open MS Access Form
    By jesika in forum Access Tables & Databases
    Replies: 0
    Last Post: 05-30-2009, 05:01 AM
  5. Open Access Report
    By Rose0402 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-31-2008, 11:36 AM
  6. Get the name of all workbooks open from access
    By Xav in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2005, 03:50 PM
  7. open excel from Access
    By dar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-06-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1