how to connect to other access datbase

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahul2310
    New Member
    • Oct 2013
    • 62

    #1

    how to connect to other access datbase

    When we want to connect to database we simply write
    Code:
    set db= current db
    What if i want to connect to other access database
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Code:
    Dim zdb as DAO.Database
    set zdb = Opendatabase( [full path and name of file] )
    Will work for Access databases.
    There are various other methods for connecting to MySQL, SQLServer, ORACLE, etc...
    Last edited by zmbd; Dec 4 '13, 01:38 PM.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      You can also use the OpenCurrentData base() Method to open an external Access Database via Automation, but within the context of the Current Database.
      1. The following Code Sample will Open an Access Database within the Current DB, Open a Form from that DB, then Close it at some point.
        Code:
        'Include the following in Declarations section of Module.
        Dim appAccess As Access.Application
        Code:
        'Initialize string to database path.
        Const conPATH_TO_DB = "C:\Business\2013\Invoices.mdb"
        
        'Create new instance of Microsoft Access.
        Set appAccess = CreateObject("Access.Application")
        
        'Open Database in Microsoft Access window.
        appAccess.OpenCurrentDatabase conPATH_TO_DB
        
        'Open Orders form.
        appAccess.DoCmd.OpenForm "frmInvoices"
        Code:
        'Close the Database at some point
        appAccess.CloseCurrentDatabase

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        rahul2310
        FYI:

        ----------
        application.ope ncurrentdatabas e method (access)
        office 2010
        don't confuse the opencurrentdata base method with the activex data objects (ado) open method or the data access object (dao) opendatabase method. The opencurrentdata base method opens a database in the microsoft access window. The dao opendatabase method returns a database object variable, which represents a particular database but don't actually open that database in the microsoft access window.
        ----------

        Comment

        Working...