ACC1x: "Fieldname" Is Not an Index in This Table

ID: 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

'<Fieldname>' isn't an index in this table.

where <Fieldname> 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 = "PrimaryKey" 


MORE INFORMATION

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

Steps to Reproduce Behavior


  1. 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("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 


  2. From the View menu, choose the Immediate window.


  3. Enter the following statement in the Immediate window:
    ? FINDID("1")
    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.


  4. Change the EMPTable.Index statement to the following:
    EMPTable.Index = "PrimaryKey"


  5. Repeat step 3.

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



REFERENCES

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
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.