Learn how to a build a cloud-first strategyRegister Now


Replication and synchronization

Posted on 2006-05-30
Medium Priority
Last Modified: 2009-07-29
HEllo Experts,

I would like to know if I can replicate and synchronize auomatically with acommand button on database form.

I am using access 2003 database ,how shall i code for this, I have created an command button and would like to put code for the above.

please need help from u,right nowas its urgent , if u can.

Question by:rachelee
  • 8
  • 6

Expert Comment

ID: 16788775

Author Comment

ID: 16788810
here its given about how shall i make it programmically, but i am new to database , will u please let me know how shall i write it in code?


Author Comment

ID: 16788811
I need replikation and synchronisation to be done by just one command button on the form

thnx again#Rachel
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 16788841

Author Comment

ID: 16788977
well, thanx a lot, i will try and get back to u soon


Author Comment

ID: 16789000
well, I did read all, but i dont know how to apply on my database,

will u please tell me how shall i code it , shall I start with replica and then synchronisation, and which code i have to write if my path is "H:\share\mean.mdb"

please tell me

Expert Comment

ID: 16789083
did you see the codes in

in a form in access create a button right click it and chose build event..then write the code of creating the replica ...and then to syncronize..in the event...



Author Comment

ID: 16796458
when i open the built event  I can see the below codes writeen ,

1)is that code correct?
2)where shall i write my replication and synchronization code?

thank you

Expert Comment

ID: 16796653
no you can can delete the built in event code of that button and write your own code inside in this case you write the rep and sync code in the event of the button

Author Comment

ID: 16796805
which replication codes shall i follow, the below one is for sync is that right line?.
if this is not correct code , what changes shall i make in this

Private Sub Befehl25_Click()
On Error GoTo Err_Befehl25_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Project"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    CurrentDb.Synchronize "H:\Test.mdb", dbRepImpExpChanges

    Exit Sub

    MsgBox Err.Description
    Resume Exit_Befehl25_Click
End Sub

please let me know now...if uhave time..I want to finish it by today.

Expert Comment

ID: 16796903
it seems fine to me..  but i am not familiar with the exact syntax..especially  On Error..but else it is good..

Author Comment

ID: 16796974
no its giving me error like ,
type of synchronization is not valid???

how abt that?


Expert Comment

ID: 16797113
try to read this and follow the way the code did.....


Synchronizing Data
Synchronizing two replicas involves exchanging data and design changes. Synchronization can be bidirectional (that is, changes in each replica are propagated to the other), or it can occur in a single direction.

Microsoft Jet also supports two styles of synchronization:

Direct synchronization is when the synchronization process has a direct connection to both replicas and is able to open both replicas simultaneously. Updates are immediately read and written to both replicas.
Indirect synchronization is when there is no direct connection to the remote replica. Instead the local replica collects its updates into a "message" file, which is written to a predetermined location, referred to as a dropbox folder. At some later time, the remote replica looks at its dropbox folder, reads the message file and applies the updates. Indirect synchronization can either send the message file over the file system or the Internet or an intranet.
Direct synchronization is the default method used by Microsoft Jet replication and is ideal when the replicas are on a local area network (LAN). Direct synchronization is usually a poor choice when replicas are physically dispersed and synchronization is over a wide area network (WAN) or dial-up connection.

Indirect synchronization is almost always the better choice for synchronizing dispersed replicas over a WAN or dial-up connection. With indirect synchronization, you never open the remote replica over a potentially unreliable communications link. Instead synchronization occurs in two phases, with each phase being controlled by a process running locally to each replica. Since you are never opening a replica remotely, indirect synchronization is both fast and robust.

The following code demonstrates how to synchronize changes between two replicas. The first example shows how to do a direct, two-way synchronization.

Sub TwoWayDirectSync(strReplica1 As String, _
                     strReplica2 As String)
   Dim repReplica  As New JRO.Replica

   repReplica.ActiveConnection = strReplica1

   ' Sends changes made in each replica to the other.
   repReplica.Synchronize strReplica2, jrSyncTypeImpExp, _

   Set repReplica= Nothing
End Sub

For example, to synchronize the Design Master of the Northwind database with a member of its replica set, you would use the following line of code:

TwoWayDirectSync "c:\NorthwindDM.mdb", "c:\NwindReplica2.mdb"

The following example shows how to do a two-way synchronization over the Internet.

Note   To configure an Internet or intranet server so that you can synchronize replicas, you must install Replication Manager, which is available with Microsoft Office 2000 Developer. For more information about installing and running Replication Manager, see Microsoft Office 2000 Developer Help. For the latest information about configuring and running Replication Manager, search the Office Developer product section of the Microsoft Support Online Web site (http://support.microsoft.com/support/default.asp) for the keyword phrase "Replication Manager."
Sub InternetSync(strLocalReplicaPath As String, _
                 strServerReplicaURL As String)
   Dim repLocalReplica  As New JRO.Replica

   repLocalReplica.ActiveConnection = strLocalReplicaPath

   ' Synchronize the local replica with the replica on
   ' the Internet server.
   repLocalReplica.Synchronize strServerReplicaURL, jrSyncTypeImpExp, _

   Set repLocalReplica = Nothing
End Sub

For example, to synchronize the OrderEntry.mdb replica on your local machine with the Orders.mdb replica on the Internet server, you would use the following line of code:

InternetSync "c:\Data\OrderEntry.mdb", "www.mycompany.myserver.com/files/Orders.mdb"

The JRO and DAO code for performing a two-way, direct synchronization between two replicas is similar. However, note that the JRO Synchronize method has an additional SyncMode argument that specifies whether the synchronization is direct (jrSyncModeDirect) or indirect (jrSyncModeIndirect). For functionality equivalent to DAO, you must specify jrSyncModeDirect when calling the Synchronize method. If you omit the SyncMode argument, the synchronization will be performed indirectly. The ability to programmatically perform indirect synchronizations is a new feature in JRO, designed to increase performance when you are synchronizing over a WAN. For more information about performing indirect synchronizations, see "Indirect Synchronization" later in this document.

The following table shows the mapping between the constants taken by the DAO Exchange argument of the Synchronize method and the constants taken by the JRO SyncType and SyncMode arguments.

Exchange:=dbRepExportChanges SyncType:=jrSyncTypeExport
Exchange:=dbRepImportChanges SyncType:=jrSyncTypeImport
Exchange:=dbRepImExpChanges SyncType:=jrSyncTypeImpExp
Exchange:=dbRepSyncInternet SyncMode:=jrSyncModeInternet

Author Comment

ID: 16797325
Thnx ,

Actually i have been seeing it since long time, but could not use in codes, thta did not work.

will u please tell me how shall i put it in code, if u have done it before??

LVL 65

Accepted Solution

rockiroads earned 2000 total points
ID: 16836742
example on how to setup

1. create your master db, has all your forms, queries, tables etc etc etc in it
2. on this form, create a button, either on a new form or an existing form where u want the synchronisation to take place
3. decide on a location for this master db (this is simple way, fancy way would be to prompt for the location)
4. this is the code to put in

    Dim dbMaster As DAO.Database
    'Open the Master database
    Set dbMaster = opendatabase("C:\EE\Replication\Master.mdb")
    'This line sends changes made in each replica to the other i.e. Master to Replica and vice versa
    dbMaster.Synchronize CurrentProject.Path & "\" & CurrentProject.Name, dbRepImpExpChanges
    MsgBox "Done"

5. Ensure u have Microsoft DAO object library set

Thats your master complete,

Now select Tools/Replication/Create Replica

this now creates a replicated database

Now try a test, add some data to master, add different data to same table but in replicate

now in replica, hit this button, it will then start synching

now check the data in both databases, u should find it matches


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question