aziz rasul
Active member
- Local time
- Today, 00:09
- Joined
- Jun 26, 2000
- Messages
- 1,935
Why does this code work: -
but this doesn't i.e. it deletes the first of two indexes but errors when it should delete the second index but IndexName still holds the name of the deleted index and comes up with an error item not in collection.
Code:
For i = 0 To DBEngine(0)(0).TableDefs("Sheet1").Indexes.Count - 1
IndexName = DBEngine(0)(0).TableDefs("Sheet1").Indexes(i).Name
CurrentDb.Execute "DROP INDEX [" & IndexName & "] ON Sheet1;"
Next i
but this doesn't i.e. it deletes the first of two indexes but errors when it should delete the second index but IndexName still holds the name of the deleted index and comes up with an error item not in collection.
Code:
For i = 0 To CurrentDb.TableDefs("Sheet1").Indexes.Count - 1
IndexName = CurrentDb.TableDefs("Sheet1").Indexes(i).Name
CurrentDb.Execute "DROP INDEX [" & IndexName & "] ON Sheet1;"
Next i