Creating a New Class Key

This section describes how to create a key as the unique identifier for a class. The class must exist prior to creating the key. Keys may be single or multi-membered.

For a single valued key there are two methods of creation.

  • Implicitly create the key by setting the value of the GenerateKeyDef attribute of the Class Definition table and the IsPrimaryKey attribute of the Member Definition corresponding to the key both equal to True (1). Explicitly creating a new instance in the Class Key Definition table is then unnecessary.

  • Explicitly create the key in a two step process. The first step is to insert a new instance in the Class Key Definition (ClsKeyDef) table, populating the attributes, and saving the changes. For information about the Class Key Definition table, see Key Definition Meta-data. The second step is to define the member of the key through the Class Key Member (KeyMem) table. For information about this step, see Creating a New Class Key Member.

For multi-membered keys, only the second method is available.

We continue our example (which originated in Creating a New Class) by creating the (multi-membered) key for the OrderFormHeader class.

The following table lists the attributes and values of the Class Key Definition table for the OrderFormHeader class. Unspecified optional attributes are not shown. In the R/O column, R = required, O = optional.

Required Attribute Name Attribute Value Type R/O Purpose
ClassKeyDefName "OrderFormHeaderKey" String R Uniquely identifies the class key.
ClassDefName "OrderFormHeader" String R The name of the class for the key.
Description "Unique key for the OrderFormHeader Class." String O Describes the logical concept underlying the key.

Running Example - Step 4

Create a new key for the OrderFormHeader class.

'Create an instance in the Class Key Definition table.
   recNew.Open "ClsKeyDef/OrderFormHeaderKey", cnnConnection, _
    adModeWrite, adCreateOverwrite

'Set the attributes.
   recNew("ClassDefName") = "OrderFormHeader"
   recNew("Description") = "Unique key for the OrderFormHeader class."

'Save the new row.
   recNew("__Commit") = 1
   recNew.Fields.Update

The next step is to define the members of this key.


All rights reserved.