ACC: Field Object Type Property Returns "Invalid Operation"

Last reviewed: August 29, 1997
Article ID: Q115901
The information in this article applies to:
  • Microsoft Access version 2.0, 7.0

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you assign a variable to a property (such as Type) of a field object of an Index object, you receive the error message "Invalid Operation." This occurs for all properties except Name and Attributes.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications" manual.

NOTE: Visual Basic for Applications (used in Microsoft Access for Windows 95, version 7.0) is called Access Basic in version 2.0.

CAUSE

Field objects of an Index object have a subset of the normal properties. The only valid properties are Name and Attributes, and the Attributes property has special values. For an Index object's field object, the Attributes property represents an ascending or descending sort order.

RESOLUTION

If you need to refer to other properties of the field object, use the TableDef field object. For example, to get the Type property you could use

   x = tabledef.fields("myfield").properties("Type")

instead of:

   x = tabledef.indexes("Myindex").fields("myfield").properties("Type")

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb (or NWIND.MDB in version 2.0) and create a new module.

  2. Enter the following line in the Declarations section of the module:

          Option Explicit
    

  3. Enter the following code in the module:

          Function FieldType ()
    
             Dim ws As WorkSpace
             Dim db As Database
             Dim tdef As TableDef
             Dim result As String
             Dim i As Integer
    
             ' Set up the environment.
             Set ws = DBEngine.Workspaces(0)
             Set db = ws.Databases(0)
    
             ' Main routine
             Set tdef = db.tabledefs("Employees")
    
             ' The line below results in "Invalid Operation."
             result = tdef.indexes("PrimaryKey").fields(0).properties("Type")
             Debug.Print result
    
             ' Cleanup
             db.Close
             ws.Close
          End Function
    
    

  4. On the View menu, click Debug Window (Or Immediate window in version 2.0.

  5. Type the following line, and then press ENTER:

          ? FieldType()
    

    Note the resulting error message.

REFERENCES

For more information about the Index object properties, search on "Index object," and then "Index Object, Indexes Collection Summary" using the Microsoft Access for Windows 95 Help Index.

For more information about the Index object properties in Access, version 2.0, search on "Index," and then "Index Object, Indexes Collection-Summary" using the Microsoft Access Help menu.

Keywords          : kberrmsg kbprg SynRef PgmObj
Version           : 2.0 7.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb
Solution Type     : Info_Provided


================================================================================


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: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.