Although Chapter 28 discusses replicating code tables, I thought it would be worthwhile to look briefly at ap_CheckReplicatedTables in this chapter (see Listing 27.6).
First, the code needs to see whether any records in the tblReplicatedTables back-end table have more recent time stamps than those in the front-end version. The back-end table is linked to the front end as tblBackEndReplicatedTables. The first lines of code make sure that the link to compare the tables isn't already existing:
catLocal.Tables.Delete "tblBackEndReplicatedTables" catLocal.Tables.Refresh On Error GoTo Error_ap_CheckReplicatedTables ap_CreateLinkedTableWithADO catLocal, "tblBackEndReplicatedTables", _ "tblReplicatedTables", pstrBackEndPath & pstrBackEndName catLocal.Tables.Refresh Set cmdUpdateRep = _ catLocal.Procedures("qryUpdateLastReplication").Command rstCheckRep.Open "qryCheckBackEndReplication", _ CurrentProject.Connection, adOpenStatic
After deleting the table if it exists, the next code line calls the ap_CreateLinkedTableWithADO routine, which creates a single ADO linked table. This is convenient if you have to do this at one time or another in an application. Here's the code for ap_CreateLinkedTableWithADO:
Sub ap_CreateLinkedTableWithADO(catCurr As ADOX.Catalog, _ strDestTableName As String, strSourceTableName As String, _ strDataMDB As String) Dim tblCurr As New ADOX.Table tblCurr.Name = strDestTableName Set tblCurr.ParentCatalog = catCurr tblCurr.Properties("Jet OLEDB:Link Datasource") = strDataMDB tblCurr.Properties("Jet OLEDB:Create Link") = True tblCurr.Properties("Jet OLEDB:Remote Table Name") = strSourceTableName catCurr.Tables.Append tblCurr End Sub
The code for ap_CheckReplicatedTables goes on to set a reference to the command object and to the qryUpdateLastReplication query:
Set cmdUpdateRep = _ catLocal.Procedures("qryUpdateLastReplication").Command
The last code segments for ap_CheckReplicatedTables perform the following tasks for each table that needs to be replicated:
And there you go. Hopefully, this will help you get going using ADO in your code.
3.15.219.80