See Also Example (Professional Edition Only)
Applies To
Index object.
Description
Determines whether an Index allows records with duplicate values in key fields. This property is read-only if the Index is a member of the Indexes collection of a TableDef. Read/write only in the Professional Edition with a new object not yet appended to a collection.
Usage
indexobject.Unique [ = { True | False }]
Setting
The Unique property settings are:
Setting Description
True Records must be unique.
False Records need not be unique.
Remarks
If the Unique property of indexobject is True, then no two records can contain the same data value in the listed key fields. An attempt to add or edit a record that results in a duplicate unique key generates an error when the record is updated.
With a data control, the Index must be a member of an Indexes collection. To get the value of the Unique property, you can use the TableDefs collection of the Database property of a data control. For example:
If Data1.Database.TableDefs("Areas").Indexes("Full Name").Unique Then...
In the Professional Edition, you can also use an object variable You can create a new Index in a Table by creating a New Index object, setting its properties, then adding it to the Indexes collection of the table's TableDef object with the Append method.
Data Type
Long
Help:
Append Method
Fields Property
Indexes Collection
New
TableDef Object
Update Method
Data Access Guide:
Chapter 2, "Database Management Using Visual Basic"
Index (Data Access), Unique Properties Example (Professional Edition Only)
This example adds a new Index to a TableDef, then makes that index the current index, and creates a Dynaset based on the Table.
Const DB_TEXT = 10 ' Type = Text.
Dim Tb As Table, Dn As Dynaset
TempIndex As New Index ' Create a new object.
TempIndex.Name = "PubID Name" ' Set Index properties.
TempIndex.Fields = "PubID;Name"
TempIndex.Unique = True
' Append the new Index to the Indexes collection
MyDB.TableDefs("Publishers").Indexes.Append TempIndex
Set Tb = MyDB.OpenTable("Publishers") ' Open the table.
Tb.Index = "PubID Name" ' Set table's current index.
Set Dn = Tb.CreateDynaset() ' Create Dynaset on the table.