Multiple Fields on an Index

  • Thread starter Jonathan Scott via AccessMonster.com
  • Start date
J

Jonathan Scott via AccessMonster.com

Is it possible to find out which fields are included on an index, within
the code? When I retrieve all the properties on an Index on a table, I can
get the name and other properties, but I don't have a clue as to how I can
get the names of the columns on the index.

Does anyone know how to achieve this, and can give me pointers or sample
code?

TIA,
Jonathan Scott
 
J

Jonathan Scott via AccessMonster.com

I should have also mentioned this is in Access97.

TIA,
Jonathan Scott
 
A

Allen Browne

This example shows how to list the indexes on a table, and the fields of
each index:

Function ShowIndexes(strTable As String)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim ind As DAO.Index
Dim fld As DAO.Field

Set db = CurrentDb()
Set tdf = db.TableDefs(strTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary, "Primary", ""), _
IIf(ind.Foreign, "Foreign", ""), ind.Fields.Count
Debug.Print " Field(s): ";
For Each fld In ind.Fields
Debug.Print fld.Name;
Next
Debug.Print
Next

Set ind = Nothing
Set tdf = Nothing
Set db = Nothing
End Function
 
J

Jonathan Scott via AccessMonster.com

Thanks Allen,

I was really asleep at the wheel on that one. That much should have been
obvious.

Thanks again,
Jonathan Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top