Before you convert a database, you might want to determine whether the database is already replicable. You can check whether the Replicable or ReplicableBool property exists in the Properties collection of the Database object. If a database has been made replicable, both properties exist in the Properties collection of the Database object.
Note that you may want to make a copy of the nonreplicable database before you make the database replicable. Microsoft Jet doesn’t do this for you automatically.
The following code makes a database replicable by setting its ReplicableBool property to True. If the ReplicableBool property doesn’t exist, it is first created and appended and then set to True:
Function MakeDbReplicable(strDbPath As String) As Boolean Dim dbs As Database Const conErrPropNotFound = 3270 On Error GoTo Err_MakeDbReplicable ' To create a replica, the database must be opened in exclusive mode. ' You open the database in exclusive mode by setting the options ' argument of the OpenDatabase method to True. If you try to open the ' current database exclusively in Microsoft Access, and you already have ' it open in shared mode, you'll get an error. Close the current database ' and reopen it in exclusive mode. ' To determine whether the database can be opened exclusively, use the ' CanOpenDbExclusively function defined in Chapter 2. If CanOpenDbExclusively(strDbPath) Then Set dbs = OpenDatabase(strDbPath, True) Else MsgBox "Database must be open in exclusive mode to make replicable." Exit Function End If ' Does the ReplicableBool property exist? dbs.Properties("ReplicableBool") = True MakeDbReplicable = True Exit_MakeDbReplicable: On Error Resume Next dbs.Close Set dbs = Nothing Exit Function Err_MakeDbReplicable: If Err = conErrPropNotFound Then ' Add the ReplicableBool property to the database's Properties ' collection and set its value to True. Use the SetCustomProperty ' function defined in Chapter 2. If SetCustomProperty(dbs, "ReplicableBool", dbBoolean, True) Then Resume Next End If End If MsgBox "Error: " & Err.Number & " - " & Err.Description MakeDbReplicable = False Resume Exit_MakeDbReplicable End Function
To create a Design Master by using DAO code, you must set the options argument of the OpenDatabase method to True to open the database exclusively. You cannot make a database replicable if it is currently open. During the conversion process, Microsoft Jet maintains all the property settings of your original database.
Once you have created a Design Master, you can create additional replicas by using the MakeReplica method of the database object. For example, the following code fragment creates a database defined by the strPathAndName
variable that is a replica of the Design Master represented by the dbs
database variable.
strPathAndName = "C:\JetBook\Samples\NewReplica.mdb" dbs.MakeReplica strPathAndName