Even though the field may exist in the TableDef's Fields collection, you
still have to create a field to add to the Index's Fields collection.
Here's a slightly abridged version from the Help file:
Sub CreateIndexX()
Dim dbsNorthwind As Database
Dim tdfEmployees As TableDef
Dim idxCountry As Index
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set tdfEmployees = dbsNorthwind!Employees
With tdfEmployees
' Create first Index object, create and append Field
' objects to the Index object, and then append the
' Index object to the Indexes collection of the
' TableDef.
Set idxCountry = .CreateIndex("CountryIndex")
With idxCountry
.Fields.Append .CreateField("Country")
.Fields.Append .CreateField("LastName")
.Fields.Append .CreateField("FirstName")
End With
.Indexes.Append idxCountry
End With
dbsNorthwind.Close
End Sub
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Brian said:
Well, I am sure I don't understand the help very well, but I do understand
that the field is created in the table's index collection if I use the
..CreateField method. However, I also know that I can create a field in the
table manually (in table design view), then later go back and add an index,
also manually
Doesn't a field reside in the table's fields collection when it is created
without an index? If so, is the field actually moved to the index collection
when I manually add the index? I am just trying to find a way to add the
index after the fact by issuing a "hotfix" without having to get access to
table design view.