Index Property Example

This example uses the Index property to set different record orders for a table-type Recordset.

Sub IndexPropertyX()

    Dim dbsNorthwind As Database
    Dim tdfEmployees As TableDef
    Dim rstEmployees As Recordset
    Dim idxLoop As Index

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    Set rstEmployees = _
        dbsNorthwind.OpenRecordset("Employees")
    Set tdfEmployees = dbsNorthwind.TableDefs!Employees

    With rstEmployees

        ' Enumerate Indexes collection of Employees table.
        For Each idxLoop In tdfEmployees.Indexes
            .Index = idxLoop.Name
            Debug.Print "Index = " & .Index
            Debug.Print "  EmployeeID - PostalCode - Name"
            .MoveFirst

            ' Enumerate Recordset to show the order of records.
            Do While Not .EOF
                Debug.Print "    " & !EmployeeID & " - " & _
                    !PostalCode & " - " & !FirstName & " " & _
                    !LastName
                .MoveNext
            Loop

        Next idxLoop

        .Close
    End With

    dbsNorthwind.Close

End Sub