Microsoft KB Archive/97001

{|
 * width="100%"|

ACC1x: &quot;Fieldname&quot; Is Not an Index in This Table

 * }

Q97001

-

The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

-

SYMPTOMS
When you run an Access Basic function that attempts to perform a Seek method on a table, you receive the following error message

'' isn't an index in this table.

where  is the name of a field in your table that has been defined as an index in your function. This field is also the primary key in the table.

CAUSE
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.

RESOLUTION
Change the statement in your function that sets the current Index property. The correct syntax should resemble the following:

  EMPTable.Index = &quot;PrimaryKey&quot;

MORE INFORMATION
The following example is based on the sample database NWIND.MDB:

Steps to Reproduce Behavior
  Create a new module and enter the following function:

     '********************************************* '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(&quot;Employees&quot;) EMPTable.Index = &quot;EMPLOYEE ID&quot; EMPTable.Seek &quot;=&quot;, EMPLOYID If EMPTable.NoMatch Then MsgBox &quot;Not a valid ID. Try another&quot; Else MsgBox &quot;This Employee ID is in the table!&quot; End If        EMPTable.Close End Function  From the View menu, choose the Immediate window.  Enter the following statement in the Immediate window:

"? FINDID(&quot;1&quot;)" You will see the following error message:

'Employee ID' isn't an index in this table.

NOTE: The Employee ID field has been defined as the primary key in the Employees table.   Change the EMPTable.Index statement to the following:

"EMPTable.Index = &quot;PrimaryKey&quot;" Repeat step 3.

You will see the appropriate message box indicating whether you entered a valid number.