I'm going to assume we're talking about the DAO Index property here, as this
is the DAO newsgroup (ADO has an Index property too).
If you look at the Employees table from the Northwind sample database in
design view, and choose Indexes from the View menu, you'll see that it has
three indexes, LastName, PostalCode, and PrimaryKey, each index using one
field, LastName, PostalCode, and EmployeeID, respectively. The following
example will Debug.Print the names and postal codes from this table, first
using the LastName index, then using the PostalCode index ...
Public Sub DemoIndex()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Employees", dbOpenTable)
With rst
.Index = "LastName"
.MoveFirst
Do Until .EOF
Debug.Print !LastName, !FirstName, !PostalCode
.MoveNext
Loop
Debug.Print
.Index = "PostalCode"
.MoveFirst
Do Until .EOF
Debug.Print !LastName, !FirstName, !PostalCode
.MoveNext
Loop
.Close
End With
End Sub
Note that we could have acheived the same result by opening the recordset
using a SQL Statement with an ORDER BY clause ...
Set rst = db.OpenRecordset("SELECT LastName, FirstName, PostalCode FROM
Employees ORDER BY LastName")
.... and that this may be more efficient.
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.