Microsoft KB Archive/107362

= FIX: Name Not Found in This Collection When Deleting Member =

Article ID: 107362

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q107362



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.



Steps to Reproduce Problem
 Start a new project in Visual Basic. Form1 is created by default. 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. Add a command button to Form1.  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  Start the program or press the F5 key. The program gives the incorrect error, "Name not found in this collection."</li></ol>

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 query words: buglist3.00 3.00 fixlist4.00

Keywords: kbbug kbfix KB107362

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.