ACC1x: "Fieldname" Is Not an Index in This TableID: Q97001
|
When you run an Access Basic function that attempts to perform a
Seek method on a table, you receive the following error message
'<Fieldname>' isn't an index in this table.
When you set the Index property in your function and you are referring to a primary key field, you should refer to the field as PrimaryKey; that is, do not refer to the field by the name of the field.
Change the statement in your function that sets the current Index
property. The correct syntax should resemble the following:
EMPTable.Index = "PrimaryKey"
The following example is based on the sample database NWIND.MDB:
'*********************************************
'Declarations section of the module.
'*********************************************
Option Explicit
'=============================================
' This FINDID function accepts one parameter.
'=============================================
Function FINDID (EMPLOYID As String)
Dim db As Database, EMPTable As Table
Set db = CurrentDB()
Set EMPTable = db.OpenTable("Employees")
EMPTable.Index = "EMPLOYEE ID"
EMPTable.Seek "=", EMPLOYID
If EMPTable.NoMatch Then
MsgBox "Not a valid ID. Try another"
Else
MsgBox "This Employee ID is in the table!"
End If
EMPTable.Close
End Function
? FINDID("1")You will see the following error message:
NOTE: The Employee ID field has been defined as the primary key in the Employees table.'Employee ID' isn't an index in this table.
EMPTable.Index = "PrimaryKey"
Microsoft Access "Introduction to Programming," version 1.0, page 114
Additional query words: seek find
Keywords : kbprg PgmObj
Version : 1.0 1.1
Platform : WINDOWS
Issue type :
Last Reviewed: March 20, 1999