CopyDatabaseFile Action

You can use the CopyDatabaseFile action to make a copy of the current Microsoft SQL Server 7.0 or later database connected to your Microsoft Access project. Access detaches the current database and then attaches it the destination server. For more information on detaching and attaching a database, see the SQL Server documentation.

Setting

The CopyDatabaseFile action has the following arguments.

Action argument Description
Database File Name The name of the new Master Data File (.mdf) file. The default path for the file is the current location of the Access project file (.adp).
Overwrite Existing File Specifies whether or not to replace an existing file with the same name. If set to Yes and the filename already exists, the file is overwritten. If set to No and the filename already exists, the file is not overwritten and the action fails. If the file doesn’t already exist, this setting is ignored. The default is Yes.
Disconnect All Users Specifies whether or not Access should force users off the database. If set to Yes, any users that are connected to the current database are forced off so the copy database operation can proceed. If set to No and one or more users are connected to the database, than the copy database operation fails. The default is No.

Caution   Forcing users off a database without adequate warning can lead to data loss.

Remarks

The copy operation is synchronous, so you cannot perform other operations until the copy of the database is complete.

CopyDatabaseFile action not only copies data, data definitions, database objects, but also extended properties, such as default values, text constraints, and lookup values.

There are requirements for copying a database:

To run the CopyDatabaseFile action in Visual Basic, use the CopyDatabaseFile method of the DoCmd object.