Replicating Objects

When you create additional replicas from your Design Master you may choose to replicate all objects or keep some objects local and prevent them from being replicated. You can set object replicability with the SetObjectReplicability method. This method requires three arguments: a string indicating the name of a table or query, the string "Tables," and a Boolean value of True if the object is to be replicable, or False otherwise.

©Hands-On 18-4: Checking If an Object is Replicable

1. Open the Design Master named DM_Northwind.mdb. (This Design Master was created by the procedure in Hands-On 18-1.)

2. In the DM_Northwind Design Master database, create a new query named SampleQuery based on any available tables. For example, you can use the following SQL statement to create the sample for this hands-on:

SELECT Employees.LastName, Employees.FirstName, Orders.OrderDate, Orders.ShipCity, Orders.ShipCountry FROM Employees

INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID;

Creating and Manipulating Databases with ADO

Upon creation, the SampleQuery object is local to your database. To confirm this, right-click the query name in the Database window and choose Properties from the shortcut menu. Notice that the Replicable check box is not checked.

Figure 18-2: When you open the Design Master file you will notice different icons in front of object names that are replicable. The local query you created in step 2 is highlighted in this screen shot.

Èp DM_Northwind : Design Master (Access 2000 file format]

Objects

l^J Create query in Design vfew

Products Above Average Price

3 Tables

ffij Create query by using wizard

Products by Category

J

Queries

Alphabetical List of Products

Quarterly Orders

jfjgl Category Sales for 1997 j^SjJi Current Product List

B^ Quarterly Orders by Product r^^ Sales by Category

21

Forros

y

Reports

Customers and Suppliers by City

Sales by Year

Pages

Employee Sales by Country

^ Sales Totals by Amount

-?

ForOataShapmg

dt

Modules

Invokes Invoices Flter

Summary of Sates by Quarter Summary of Sales by Year

Groups

Order Details Extended

Ten Most Expensive Products

_±J

Favtrftes

Order Subtotals ■jjfo OrdersQry JJ^j Product Sales for 1997

Samp leQue ry P rope rties [*X ]

I Gereal j

fT^-1 SampleQuery

Type:

Query: Select Query (Local)

Description:

Created: 3/12/2004 12:05:42 PM Modfied: 3/12/2004 12:05:42 PM Owner; Admin

Attributes: □ Hidden DRepficatJe

1 ÜK 1 Cancel 1

Figure 18-3: You can determine whether a certain database object is replicable or not by checking the object's properties. The Replicable check box is not checked for local objects.

If at this time you create an additional replica from the Design Master or try to synchronize with an existing replica, this new query object will not be replicated. To ensure the new object is replicated, you can check the Replicable property in the Properties box (Figure 18-3 above) or set the object's replicability in VBA code by using the SetObjectReplicability method. We will set the replicability of the SampleQuery object in the procedure code in Hands-On 18-5.

3. Close the DM_Northwind database without checking the Replicable property for the SampleQuery object.

Part II

©Hands-On 18-5 : Making an Object Replicable

1. Switch to the Visual Basic Editor window and insert a new module.

2. In the module's Code window, enter the MakeObject_Replicable procedure as shown below.

Sub MakeObject_Replicable(repName As String, objName As String) Dim repDesignMaster As New JRO.Replica With repDesignMaster

.ActiveConnection = repName .SetObjectReplicability objName, "Tables", True End With

Set repDesignMaster = Nothing MsgBox objName & " is now replicable." End Sub

The procedure in Hands-On 18-5 takes two arguments: the full path of your Design Master and the object name you want to make replicable.

3. Run the MakeObject_Replicable procedure from the Immediate window by typing the following statement and pressing Enter:

MakeObject_Replicable CurrentProject.Path & "\DM_Northwind.mdb", "SampleQuery"

4. Open the Design Master DM_Northwind.mdb file and switch to the queries pane. Notice that SampleQuery is now replicable.

0 0

Post a comment