CopyDatabaseFile Method

       

Copies the database connected to the current project to a Microsoft SQL Server database file for export.

expression.CopyDatabaseFile(DatabaseFileName, OverwriteExistingFile, DisconnectAllUsers)

expression   Required. An expression that returns a DoCmd object.

DatabaseFileName  Required Variant. The name of the file (and path) to which the current database is copied. If no path is specified, the current directory is used.

OverwriteExistingFile  Optional Variant. Determines whether Microsoft Access overwrites the file specified by DatabaseFileName. True to overwrite the existing file. If the file doesn't already exist, this argument is ignored.

DisconnectAllUsers  Optional Variant. Determines whether Access disconnects any users connected to the current database in order to make the copy. True to disconnect other users before copying the database file.

Remarks

The file name of the copy must have an .mdf extension in order to be recognized as a SQL Server database file.

The method fails and an error occurs if any of the following occurs:

Example

This example copies the database connected to the current project to a SQL Server database file. If the file exists already, Access overwrites it, and any other users connected to the database are disconnected before the copy is made.

DoCmd.CopySQLDatabaseFile _
    DatabaseFileName:="C:\Export\Sales.mdf", _
    OverwriteExistingFile:=True, _
    DisconnectAllUsers:=True