Synchronize Method
Applies To
Database object.
Description
Synchronizes two replicas. (Microsoft Jet databases only).
Syntax
database.Synchronize pathname, exchange
The Synchronize method syntax has the following parts.
Part | Description |
|
database | An object variable that represents a Database object that is a replica. |
pathname | A String that contains the path to the target replica with which database will be synchronized. The .mdb file name extension is optional. |
exchange | Optional. A constant indicating which direction to synchronize changes between the two databases, as specified in Settings. |
Settings
You can use the following constants in the exchange argument. You can use one of the first three constants with or without the fourth constant.
Constant | Description |
|
dbRepExportChanges | Sends changes from database to pathname. |
dbRepImportChanges | Sends changes from pathname to database. |
dbRepImpExpChanges | (Default) Sends changes from database to pathname, and vice versa, also known as bidirectional exchange. |
dbRepSyncInternet | Exchanges data between files connected by an Internet pathway. |
Remarks
You use Synchronize to exchange data and design changes between two databases. Design changes always happen first. Both databases must be at the same design level before they can exchange data. For example, an exchange of type dbRepExportChanges might cause design changes at a replica even though data changes flow only from the database to pathname.
The replica identified in pathname must be part of the same replica set. If both replicas have the same ReplicaID property setting or are Design Masters for two different replica sets, the synchronization fails.
When you synchronize two replicas over the Internet, you must use the dbRepSyncInternet constant. In this case, you specify a Uniform Resource Locator (URL) address for the pathname argument instead of specifying a local area network path.
Note You can't synchronize partial replicas with other partial replicas. See the PopulatePartial method for more information.
Example
These four examples use the Synchronize method to demonstrate one-way and bi-directional exchanges of information between two members of a replica set. They will work if you have converted Northwind.mdb to a Design Master (see the Replicable Property), and created a replica from it. The replica name specified is Nwreplica.mdb. Change the name of the replica to fit your situation, or use the MakeReplica method to create a replica if you need one.
This example sends the changes from the Northwind Design Master to Nwreplica. Adjust the paths to the locations of the files on your computer.
Sub SendChangeToReplicaX()
Dim dbsNorthwind As Database
' Opens the replicable database Northwind.mdb.
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' Sends data or structural changes to the replica.
dbsNorthwind.Synchronize "Nwreplica.mdb", _
dbRepExportChanges
dbsNorthwind.Close
End Sub
In this example, the replicable database Northwind.mdb receives changes from the replica in the path — Nwreplica. You must run this procedure from the database receiving the changes.
Sub ReceiveChangeX()
Dim dbsNorthwind As Database
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' Sends changes from replica to Design Master.
dbsNorthwind.Synchronize "Nwreplica.mdb", _
dbRepImportChanges
dbsNorthwind.Close
End Sub
In this example, changes from both the replicable database Northwind and a replica are exchanged. This is the default argument for this method.
Sub TwoWayExchangeX()
Dim dbsNorthwind As Database
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' Sends changes made in each replica to the other.
dbsNorthwind.Synchronize "Nwreplica.mdb", _
dbRepImpExpChanges
dbsNorthwind.Close
End Sub
The following code sample synchronizes two databases over the Internet.
Sub InternetSynchronizeX()
Dim dbsTemp As Database
Set dbsTemp = OpenDatabase("C:\Data\OrdEntry.mdb")
' Synchronize the local database with the replica on
' the Internet server.
dbsTemp.Synchronize _
"www.mycompany.myserver.com" _
& "/files/Orders.mdb", _
dbRepImpExpChanges + dbRepSyncInternet
dbsTemp.Close
End Sub