FIX: Name Not Found in This Collection When Deleting Member

Last reviewed: October 30, 1997
Article ID: Q107362
3.00 WINDOWS kbprg kbbuglist

The information in this article applies to:

- Professional Edition of Microsoft Visual Basic for Windows,

  version 3.0

SYMPTOMS

The Delete method incorrectly reports the following message for the existing member under certain conditions:

   Name not found in this collection. Error 3265.

This occurs when you use the OpenDatabase function to open a database, and then immediately, as the first change to the database's structure, execute a Delete method on a member of a TableDefs or Indexes collection. The member can be a TableDef or Index.

CAUSE

The problem occurs when a Delete method is the first data definition language (DDL) operation after you open the database.

WORKAROUND

To work around the bug, use the Refresh method on the Indexes collection before using the Delete method. An example is shown in "Workaround Example" under the More Information section below.

NOTE: A program will correctly give the above error message when the name truly is not found in the collection. As soon as a Delete method succeeds on a specified TableDef or Index member of a collection, that name will no longer be found in the collection.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem has been corrected in Visual Basic version 4.0.

MORE INFORMATION

Steps to Reproduce Problem

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Copy the file BIBLIO.MDB from your Visual Basic directory to the root directory (C:\BIBLIO.MDB). The program created below modifies the copy of BIBLIO.MDB instead of the master file. The BIBLIO.MDB sample database file is a bibliographical reference.

  3. Add a command button to Form1.

  4. Add the following code to the Command1 Click event:

       Sub Command1_Click()
          Dim db as Database
          Set db = OpenDatabase ("c:\BIBLIO.MDB")
          ' db.TableDefs("Titles").Indexes.Refresh ' Add this for workaround
          db.Tabledefs("Titles").Indexes.Delete "PubID"  '<- Problem line
       End Sub
    
    

  5. Start the program or press the F5 key. The program gives the incorrect error, "Name not found in this collection."

Workaround Example

To work around this bug, use the Refresh method before using the Delete method:

   db.TableDefs("Titles").Indexes.Refresh

As an alternative workaround, replace the Delete line with this command:

   ' Enter the following two lines as one, single line:
   db.TableDefs("Titles").Indexes.Delete
      db.TableDefs("Titles").Indexes("PubID")

This command expands "PubID" into its complete reference:

   db.TableDefs("Titles").Indexes("PubID")

This refreshes the Indexes collection before PubID is deleted in the same statement.

NOTE: If you run the program twice using the workaround, the program correctly gives the error, "Name not found in this collection." The error is correct this time because the PubID index member was successfully deleted and no longer exists.


Additional reference words: buglist3.00 3.00 fixlist4.00
KBCategory: kbprg kbbuglist
KBSubcategory: APrgDataOther
Keywords : APrgDataOther kbbuglist kbprg
Version : 3.00
Platform : WINDOWS
Solution Type : kbfix


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