Creating a Design Master

A replica is a copy of a database. There are three types of replicas: Design Master, full replica, and partial replica. To work with replication, start by creating a backup copy of your database. You will need it in case there is a problem with the replicated database. Next, create a replica of your database by using the Replica object's MakeReplicable method. This method requires that you provide a full path to your database and indicate whether you want column-level tracking. With column-level tracking, changing different columns in the same row of a table in two replicas doesn't cause a conflict. The Make-Replicable method converts a normal Access database into a Design Master.

Creating and Manipulating Databases with ADO

This is a master replica from which you can create additional replicas with the CreateReplica method.

The Design Master is the first member of a replica set. When you create a Design Master, new system tables are added to a database and new fields are added to the existing tables. Only the Design Master can accept changes to the database structure. If the Design Master is damaged, you can promote one of the replicas to become the Design Master. Hands-On 18-1 below demonstrates how to make a backup copy of the original database and create a Design Master.

©Hands-On 18-1: Creating a Design Master

1. Open the Acc2003_Chap18.mdb file from the book's downloadable files or create this file from scratch using the Access user interface.

2. Make sure you have a copy of the Northwind database in the same folder as the Acc2003_Chap18.mdb file.

3. Switch to the Visual Basic Editor window and insert a new module.

4. Choose Tools | References and add the following two libraries: Microsoft Jet and Replication Objects Library and Microsoft Scripting Runtime Library.

5. In the module's Code window, enter the Create_DesignMaster procedure as shown below.

Sub Create_DesignMaster(dbName As String, strPath As String) Dim repDesignMaster As New JRO.Replica Dim fso As Scripting.FileSystemObject Dim strDb As String

' create a new instance of the FileSystemObject Set fso = New FileSystemObject

' store a file name for the Design Master in a variable strDb = strPath & "DM_" & dbName

' create a copy of the sample Northwind database If Not fso.FileExists(strDb) Then fso.CopyFile strPath & dbName, strDb

Else

MsgBox "The " & strDb & " database file already exists." Exit Sub End If

' make the database replicable repDesignMaster.MakeReplicable strDb, True MsgBox "Your Design Master was successfully created." _ , , "DM_Northwind"

Set repDesignMaster = Nothing Set fso = Nothing End Sub

Part II

To access your computer's file system, the above procedure uses the FileSystemObject from the Microsoft Scripting Runtime Library. The FileSystemObject gives you access to numerous methods and properties for working with drives, folders, and files. Notice how we use the FileExists method of FileSystemObject to find out if a file named DM_Northwind.mdb already exists in the specified folder. If the file does not exist, we use another method (CopyFile) of the FileSystemObject to create a copy of the Northwind database and name it DM_Northwind.mdb. Next, we use the MakeReplicable method of the JRO Replica object to create a master replica (Design Master).

6. To execute the Create_DesignMaster procedure, type the following statement in the Immediate window and press Enter:

Create_DesignMaster "Northwind.mdb", CurrentProject.Path & "\"

For the above statement to work you must ensure that the Northwind.mdb file is located in the same folder as the Acc2003_Chap18.mdb file you are currently working with.

After running the Create_DesignMaster procedure, the current folder should contain a database file named DM_Northwind.mdb, which is a Design Master.

0 0

Post a comment