Table-Type Recordset Object Example (MDB)
The following example opens a table-type Recordset object, then finds a specified record:
Sub FindEmployee()
Dim dbs As Database, tdf As TableDef
Dim rst As Recordset, idx As Index
Dim fldLastName As Field, fldFirstName As Field
' Return reference to current database.
Set dbs = CurrentDb
' Return reference to Employees table.
Set tdf = dbs.TableDefs!Employees
' Create new index.
Set idx = tdf.CreateIndex("FullName")
' Create and append index fields.
Set fldLastName = idx.CreateField("LastName", dbText)
Set fldFirstName = idx.CreateField("FirstName", dbText)
idx.Fields.Append fldLastName
idx.Fields.Append fldFirstName
' Append Index object.
tdf.Indexes.Append idx
' Open table-type Recordset object.
Set rst = dbs.OpenRecordset("Employees")
' Set current index to new index.
rst.Index = idx.Name
' Specify record to find.
rst.Seek "=", "Fuller", "Andrew"
If rst.NoMatch Then
Debug.Print "Seek failed."
Else
Debug.Print "Seek successful."
End If
rst.close
Set dbs = Nothing
End Sub