Keeping Objects Local

When you create a Design Master, all of the objects in the database are converted to replicable objects. If you don’t want all the objects in your database dispersed throughout the replica set, you can append and set the KeepLocal property for any objects you don’t want replicated before you create the replica. For example, if your database has a table containing confidential salary information, initialization information, or names of users who log on to the database, you might want to keep that information only in the Design Master. You can set the table’s KeepLocal property to “T” to keep it local while all other objects are replicated when the database is converted to a Design Master.

If you replicate an object with your database, you can still set that object’s ReplicableBool property to False so that the object will not be propagated to the replica set when you synchronize. The KeepLocal property is most useful when you want to make sure that an object is never made replicable at all. For example, when you replicate a table, new fields are added to the table, and any AutoNumber fields are no long simple linear sequences but instead become globally unique identifiers (GUIDs). To prevent these changes to a table, you can set its KeepLocal property before you make the database replicable.

To set the KeepLocal property of an object, you must first create the property and append it to the object’s Properties collection if it does not already exist in the collection. For a TableDef or QueryDef object, you create the KeepLocal property in the TableDef or QueryDef object’s Properties collection. For a Microsoft Access form, report, macro, or module, you create the KeepLocal property in the Properties collection of the Document object that is associated with the object you want to keep local.

The following code shows how to set the KeepLocal property for an object. If the KeepLocal property does not exist in the object’s Properties collection, the procedure creates the property, sets its value to “T”, and appends it to the object’s Properties collection. Note that the object passed in for the obj argument must be of the type TableDef, QueryDef, or Document:

Function MakeObjectLocal(obj As Object) As Boolean
	Const conErrPropNotFound = 3270
	
	On Error GoTo Err_MakeObjectLocal
	' Does the KeepLocal property exist for this object?
	obj.Properties("KeepLocal").Value = "T"
	MakeObjectLocal = True
	
Exit_MakeObjectLocal:
	Exit Function

Err_MakeObjectLocal:
	' If KeepLocal property does not exist, create the KeepLocal property
	' and set it to "T".
	If Err = conErrPropNotFound Then
		' Add the KeepLocal property to the Properties collection by
		' using the SetCustomProperty function defined in Chapter 2.
		If SetCustomProperty(obj, "KeepLocal", dbText, "T") = True Then
			Resume Next
		End If
	Else
		MsgBox "Error: " & Err.Number & " - " & Err.Description
	End If
	MakeObjectLocal = False
	Resume Exit_MakeObjectLocal
End Function

Important If the object on which you are setting the KeepLocal property has already inherited that property from another object, the value set by the other object has no effect on the behavior of the object you want to keep local. You must directly set the property for each object.

You cannot set the KeepLocal property for objects after they have been converted into a replicable form. However, to prevent an object from being propagated through the replica set, you can set its ReplicableBool property to False.

If you have created a relationship between two tables in your database, you must set the KeepLocal property the same for both tables — both tables must be local or both must be replicable. If the property is not set the same for both tables, an error occurs. The KeepLocal property cannot be set while the relationship is in effect. Before creating and setting the KeepLocal property, delete the relationship between the tables. After setting the KeepLocal property, add the relationship back to the tables and proceed with converting the database.