The following code demonstrates how to create a new index. The index is on two columns in the table.
Attribute VB_Name = "IndexesAppend"
Option Explicit
' BeignCreateIndexVB
Sub CreateIndex()
Dim tbl As New Table
Dim idx As New ADOX.Index
Dim cat As New ADOX.Catalog
'Open the catalog.
' Open the Catalog.
cat.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb;"
' Define the table and append it to the catalog
tbl.Name = "MyTable"
tbl.Columns.Append "Column1", adInteger
tbl.Columns.Append "Column2", adInteger
tbl.Columns.Append "Column3", adVarWChar, 50
cat.Tables.Append tbl
' Define a multi-column index
idx.Name = "multicolidx"
idx.Columns.Append "Column1"
idx.Columns.Append "Column2"
' Append the index to the table
tbl.Indexes.Append idx
End Sub
' EndCreateIndexVB
Append Method (Indexes) | Index Object | Indexes Collection
© 1998-2001 Microsoft Corporation. All rights reserved.