Seek Method Example

This example opens Customer.dbf (a dBASE IV table located in the C:\Program Files\Microsoft Office\Office folder), locates a record, and then copies the the record’s values into cells B2:C2 on Sheet1.

Dim db As Database, td As TableDef, idx As Index
Dim fld As Field, rs As Recordset
Set db = _
    OpenDatabase("C:\Program Files\Microsoft Office\Office", _
    False, False, "dBASE IV")
' create a temporary index
Set td = db.TableDefs("Customer")
Set idx = td.CreateIndex("CUSTMR_ID")
Set fld = idx.CreateField("CUSTMR_ID", dbText, 255)
idx.Fields.Append fld
td.Indexes.Append idx
' find the records
Set rs = db.OpenRecordset("CUSTOMER.DBF", dbOpenTable)
rs.Index = "CUSTMR_ID"
rs.Seek "=", "FOODG"
If rs.NoMatch Then
    MsgBox "Couldn't find any records"
Else
    With Sheets("Sheet1")
        .Cells(2, 2) = rs.Fields("COMPANY").Value
        .Cells(3, 2) = rs.Fields("CITY").Value
    End With
End If
rs.Close
' delete the temporary index
td.Indexes.Delete "CUSTMR_ID"
db.Close