FredixBlog


Just my log about anything I could find enjoyable.



Replicate a database

author Posted by: fredometro on date Jan 1st, 2004 | filed Filed under: MS-Access

This function replicates a database with another replica, or the master database.
The databases are secured.
Public Function RunReplication(TheMaster, TheRemote, UserName, Password)
Dim db As Database
Dim myDBE As DBEngine
Dim dbMyNewMdb As Database
Dim ws As Workspace
On Error GoTo Err_RunReplication
Set myDBE = New PrivDBEngine
myDBE.SystemDB = DBEngine.SystemDB
myDBE.DefaultUser = UserName
myDBE.DefaultPassword = Password
Set ws = myDBE.CreateWorkspace(”ws”, UserName, Password)

Set dbMyNewMdb = ws.OpenDatabase(TheMaster)

RunReplication = True

On Error Resume Next

dbMyNewMdb.Synchronize TheRemote
If Err <> 0 Then
    MsgBox Error$
    RunReplication = False
End If

On Error GoTo Err_RunReplication
dbMyNewMdb.Close
Set dbMyNewMdb = Nothing
Exit Function
Err_RunReplication:
MsgBox Error$, vbCritical
RunReplication = False

End Function