Article ID: 141612
Article Last Modified on 1/19/2007
Table: Interviews
----------------------------
Field Name: CustomerID
Data Type: Number
Field Size: Long Integer
Field Name: InterviewerID
Data Type: Number
Field Size: Long Integer
Field Name: Appointment
Data Type: Date/Time
' '---------------------------------------------------------------
'PURPOSE: Adds a multiple-field index to a table.
'ACCEPTS: Nothing.
'RETURNS: Nothing.
'---------------------------------------------------------------
Function AddMultiIndex ()
Dim dbs As Database, tdf As TableDef
Dim idx As Index, fld As Field
Set dbs = CurrentDb()
' Open the table definition.
Set tdf = dbs.TableDefs("Interviews")
' Create an index called PrimaryKey for this TableDef
' and turn on the Primary and Required properties.
Set idx = tdf.CREATEINDEX("PrimaryKey")
With idx
.Name = "PrimaryKey"
.PRIMARY = True
.Required = True
.IgnoreNulls = False
End With
' Create an index field with the same name as a table field,
' then append it to the index.
Set fld = idx.CreateField("CustomerID")
idx.Fields.Append fld
' Do the second field the same way.
Set fld = idx.CreateField("InterviewerID")
fld.Attributes = dbDescending
idx.Fields.Append fld
' Append the index to the TableDef.
tdf.Indexes.Append idx
End Function
? AddMultiIndex()
112107 ACC2: How to Index an Existing Field with DAO
Keywords: kbhowto kbprogramming KB141612