You can use the DeleteObject action to delete a specified database object (database objects: An Access database contains objects such as tables, queries, forms, reports, pages, macros, and modules. An Access project contains objects such as forms, reports, pages, macros, and modules.).
Note This action will not be allowed if the database is not trusted. For more information about enabling macros, see the links in the See Also section of this article.
The DeleteObject action has the following arguments.
||The type of object to delete. Click Table, Query, Form, Report, Macro, Module, Data Access Page, Server View, Diagram, Stored Procedure, or Function in the Object Type box in the Action Arguments section of the Macro Builder pane. To delete the object selected in the Navigation Pane, leave this argument blank.
The name of the object to delete. The Object Name box shows all objects in the database of the type selected by the Object Type argument. If you leave the Object Type box blank, leave this box blank also.
If you run a macro containing the DeleteObject action in a library database (library database: A collection of procedures and database objects that you can call from any application. In order to use the items in the library, you must first establish a reference from the current database to the library database.), Microsoft Office Access 2007 first looks for the object with this name in the library database, and then in the current database.
Warning If you leave the Object Type and Object Name boxes blank, Access deletes the object selected in the Navigation Pane without displaying a warning message when it encounters the DeleteObject action.
You can use the DeleteObject action to delete temporary objects you have created while running the macro. For example, you could use the OpenQuery action to run a make-table query (make-table query: A query (SQL statement) that creates a new table and then creates records (rows) in that table by copying records from an existing table or query result.) that creates a temporary table. When you are finished using the temporary table, you can use the DeleteObject action to delete it.
This action has the same effect as selecting an object in the Navigation Pane and then pressing the DEL key, or right-clicking the object in the Navigation Pane and clicking Delete.
To run the DeleteObject action in a Visual Basic for Applications module, you can use the DeleteObject method of the DoCmd object.