|Access Developer Reference|
You use the Database object and its methods and properties to manipulate an open database. In any type of database, you can:
- Use the Execute method to run an action query.
- Set the Connect property to establish a connection to an ODBC data source.
- Set the QueryTimeout property to limit the length of time to wait for a query to execute against an ODBC data source.
- Use the RecordsAffected property to determine how many records were changed by an action query.
- Use the OpenRecordset method to execute a select query and create a Recordset object.
- Use the Version property to determine which version of a database engine created the database.
With a Microsoft Access database engine database, you can also use other methods, properties, and collections to manipulate a Database object, as well as create, modify, or get information about its tables, queries, and relationships. For example, you can:
- Use the CreateTableDef and CreateRelation methods to create tables and relations, respectively.
- Use the CreateProperty method to define new Database properties.
- Use the CreateQueryDef method to create a persistent or temporary query definition.
- Use MakeReplica, Synchronize, and PopulatePartial methods to create and synchronize full or partial replicas of your database.
- Set the CollatingOrder property to establish the alphabetic sorting order for character-based fields in different languages.
You use the CreateDatabase method to create a persistent Database object that is automatically appended to the Databases collection, thereby saving it to disk.
You don't need to specify the DBEngine object when you use the OpenDatabase method.
Opening a database with linked tables doesn't automatically establish links to the specified external files. You must either reference the table's TableDef or Field objects or open a Recordset object. If you can't establish links to these tables, a trappable error occurs. You may also need permission to access the database, or another user might have the database opened exclusively. In these cases, trappable errors occur.
When a procedure that declares a Database object has executed, local Database objects are closed along with any open Recordset objects. Any pending updates are lost and any pending transactions are rolled back, but no trappable error occurs. You should explicitly complete any pending transactions or edits and close Recordset objects and Database objects before exiting procedures that declare these object variables locally.
When you use one of the transaction methods (BeginTrans, CommitTrans, or Rollback) on the Workspace object, these transactions apply to all databases opened on the Workspace from which the Database object was opened. If you want to use independent transactions, you must first open an additional Workspace object, and then open another Database object in that Workspace object.
|You can open the same data source or database more than once, creating duplicate names in the Databases collection. You should assign Database objects to object variables and refer to them by variable name.|
This example creates a new Database object and opens an existing Database object in the default Workspace object. Then it enumerates the Database collection and the Properties collection of each Database object.
|Visual Basic for Applications|
This example uses CreateDatabase to create a new, encrypted Database object.
|Visual Basic for Applications|