CopyObject Action

Description

You can use the CopyObject action to copy the specified database object to a different Microsoft Access database or to the same database under a new name. For example, you can copy or save an existing object in another database or quickly create a similar object with changes.

Setting

The CopyObject action uses the following arguments.

Action argument Description
Destination Database A valid path and filename for the destination database. Leave this argument blank if you want to select the current database.
If you run a macro containing the CopyObject action in a library database and leave this argument blank, Microsoft Access will copy the object into the library database.
New Name A new name for the object. When copying to a different database, leave this argument blank to keep the same name.
Source Object Type The object type you want to copy. Click Table, Query, Form, Report, Macro, or Module in the Source Object Type box in the Action Arguments section of the Macro window. To copy the object selected in the Database window, leave this box blank.
Source Object Name The name of the object to be copied. The Source Object Name box shows all objects in the database of the type selected by the Source Object Type argument. In the Source Object Type box, click the object to copy. If you left the Source Object Type blank, leave this box blank also.
If you run a macro containing the CopyObject action in a library database, Microsoft Access looks for the object with this name first in the library database, then in the current database.


Remarks

You must enter a value for either one or both of the Destination Database and New Name arguments for this action.

If you leave the Source Object Type and Source Object Name arguments blank, Microsoft Access copies the object selected in the Database window. To select an object in the Database window, you can use the SelectObject action with the In Database Window argument set to Yes.

The CopyObject action is similar to selecting an object in the Database window, clicking Copy on the Edit menu, and then clicking Paste on the Edit menu. The Paste As dialog box appears so you can give the object a new name. The CopyObject action performs all of these steps automatically.

You can also copy an object selected in the Database window, or an open object in the Table window, Query window, Form window, Report window, Macro window, or Module window by clicking Save As/Export on the File menu. The Save As dialog box gives you the option of saving a copy of the object in the current database with a new name, or saving the object in another database. If this object has already been saved and you save it in the current database with a new name, the original version still exists with its old name.

The path and filename of the destination database must exist before the macro runs the CopyObject action. If they don’t exist, Microsoft Access displays an error message.

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

See Also

CopyObject Method, Rename Action, TransferDatabase Action.