Creating Table Indexes Example
The following example creates a new Index object on an Employees table. The new index consists of two fields, LastName and FirstName.
Note A reference to "Microsoft ADO ext. 2.1 for DDL and Security" must be set to use this example.
Sub NewIndex()
Dim cat As New ADOX.Catalog, tbl As ADOX.Table
Dim idx As New ADOX.Index
' Return reference to current database.
Set cat.ActiveConnection = CurrentProject.Connection
' Return reference to Employees table.
Set tbl = cat.Tables!Employees
' Return reference to new index.
idx.Name = "FullName"
idx.Columns.Append "LastName", adVarWChar
idx.Columns.Append "FirstName", adVarWChar
tbl.Indexes.Append idx
' Append Index object and refresh collection.
tbl.Indexes.Refresh
Set cat = Nothing
End Sub