DBEngine.OpenDatabase Method

Access Developer Reference

Opens a specified database and returns a reference to the Database object that represents it.

Syntax

expression.OpenDatabase(Name, Options, ReadOnly, Connect)

expression   A variable that represents a DBEngine object.

Parameters

Name Required/Optional Data Type Description
Name Required String the name of an existing Microsoft Access database file, or the data source name (DSN) of an ODBC data source. See the Name property for more information about setting this value.
Options Optional Variant Sets various options for the database, as specified in Remarks.
ReadOnly Optional Variant True if you want to open the database with read-only access, or False (default) if you want to open the database with read/write access.
Connect Optional Variant Specifies various connection information, including passwords.

Return Value
Database

Remarks

You can use the following values for the options argument.

Setting Description
True Opens the database in exclusive mode.
False (Default) Opens the database in shared mode.

When you open a database, it is automatically added to the Databases collection.

Some considerations apply when you use dbname:

  • If it refers to a database that is already open for access by another user, an error occurs.
  • If it doesn't refer to an existing database or valid ODBC data source name, an error occurs.
  • If it's a zero-length string ("") and connect is
    Visual Basic for Applications
    
    

    "ODBC;"

    , a dialog box listing all registered ODBC data source names is displayed so the user can select a database.

    To close a database, and thus remove the Database object from the Databases collection, use the Close method on the object.

    Bb221072.vs_note(en-us,office.12).gif  Note
    When you access a Microsoft Access database engine-connected ODBC data source, you can improve your application's performance by opening a Database object connected to the ODBC data source, rather than by linking individual TableDef objects to specific tables in the ODBC data source.