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

Last reviewed: June 8, 1997
Article 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 : JetFind kbprg PgmObj
Version : 1.0 1.1
Platform : WINDOWS
Hardware : X86
Issue type : kbdocerr


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.