Back Up Selected Objects to Another Database

Problem

You use a standard backup program to save your databases, but this works only at the database level. This is fine for archival purposes, but you often want to back up individual objects. How can you get Access to display a list of objects and allow you to save selected ones to an output database you specify?

Solution

This solution shows how to create a form that selectively saves Access objects to another database. It works by using a multiselect list box and the CopyObject action.

Open frmBackup from 06-08.MDB (Figure 6-11). You can use this form to back up selected objects from the current database to another database. Select one or more objects from the list box, using the Shift or Ctrl keys to extend the selection. When you are finished selecting objects and have specified a backup database (a default database name is created for you), press the Backup button. The backup process will begin, copying objects from the current database to the backup database.

frmBackup backing up selected database objects

Figure 6-11. frmBackup backing up selected database objects

To add this functionality to your own database, follow these steps:

  1. Import frmBackup from 06-08.MDB to your database.

  2. Call the backup procedure from anywhere in your application by opening the frmBackup form. For example, you might place a command button on your main switchboard form with the following event procedure ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.