Microsoft KB Archive/107362: Difference between revisions
(importing KB archive) |
m (Text replacement - "<" to "<") |
||
(One intermediate revision by the same user not shown) | |||
Line 64: | Line 64: | ||
== WORKAROUND == | == WORKAROUND == | ||
To work around the bug, use the Refresh method on the Indexes collection before using the Delete method. An example is shown in | 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.<br /> | ||
<br /> | <br /> | ||
'''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. | '''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. | ||
Line 89: | Line 89: | ||
<pre class="codesample"> Sub Command1_Click() | <pre class="codesample"> Sub Command1_Click() | ||
Dim db as Database | Dim db as Database | ||
Set db = OpenDatabase ( | Set db = OpenDatabase ("c:\BIBLIO.MDB") | ||
' db.TableDefs( | ' db.TableDefs("Titles").Indexes.Refresh ' Add this for workaround | ||
db.Tabledefs( | db.Tabledefs("Titles").Indexes.Delete "PubID" '<- Problem line | ||
End Sub | End Sub | ||
</pre></li> | </pre></li> | ||
<li>Start the program or press the F5 key. The program gives the incorrect error, | <li>Start the program or press the F5 key. The program gives the incorrect error, "Name not found in this collection."</li></ol> | ||
=== Workaround Example === | === Workaround Example === | ||
To work around this bug, use the Refresh method before using the Delete method: | To work around this bug, use the Refresh method before using the Delete method: | ||
<pre class="codesample"> db.TableDefs( | <pre class="codesample"> db.TableDefs("Titles").Indexes.Refresh | ||
</pre> | </pre> | ||
As an alternative workaround, replace the Delete line with this command: | As an alternative workaround, replace the Delete line with this command: | ||
<pre class="codesample"> ' Enter the following two lines as one, single line: | <pre class="codesample"> ' Enter the following two lines as one, single line: | ||
db.TableDefs( | db.TableDefs("Titles").Indexes.Delete | ||
db.TableDefs( | db.TableDefs("Titles").Indexes("PubID") | ||
</pre> | </pre> | ||
This command expands | This command expands "PubID" into its complete reference: | ||
<pre class="codesample"> db.TableDefs( | <pre class="codesample"> db.TableDefs("Titles").Indexes("PubID") | ||
</pre> | </pre> | ||
This refreshes the Indexes collection before PubID is deleted in the same statement.<br /> | This refreshes the Indexes collection before PubID is deleted in the same statement.<br /> | ||
<br /> | <br /> | ||
'''NOTE''': If you run the program twice using the workaround, the program correctly gives the error, | '''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. | ||
</div> | </div> |
Latest revision as of 15:00, 20 July 2020
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:
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
- 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."
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