G
Guest
I have code that deletes an index from a table, then deletes the column containing that index
' Delete the old inde
Set dbs = currentD
dbs.TableDefs.Refres
Set tdf = dbs.TableDefs(tblName
dbs.TableDefs(tblName).Indexes.Refres
Set idxSpace = dbs.TableDefs(tblName).Indexe
For Each idxSearch In dbs.TableDefs(tblName).Indexe
If idxSearch.Name = fieldname The
MsgBox "Deleting " & idxSearch.Nam
sql = "DROP INDEX " & fieldname & " ON " & tblName & ";
currentDB.Execute sq
' Also tried it with the delete method
' currentDB.TableDefs(tblName).Indexes.Delete fieldnam
End I
Nex
dropcolumn
' Delete the old field
sql = "ALTER TABLE [" & tblName & "] DROP COLUMN [
sql = sql & fieldname & "]
qdf.sql = sq
qdf.Execut
' Rename the temporary field to the old field's name
db.TableDefs("[" & tblName & "]").Fields("AlterTempField").Name = fieldnam
When the "ALTER TABLE DROP COLUMN" sql statement executes, I get
Run-time error '3280'
Can't delete a field that is part of an index or is needed by the system
Any ideas? Thanks.
' Delete the old inde
Set dbs = currentD
dbs.TableDefs.Refres
Set tdf = dbs.TableDefs(tblName
dbs.TableDefs(tblName).Indexes.Refres
Set idxSpace = dbs.TableDefs(tblName).Indexe
For Each idxSearch In dbs.TableDefs(tblName).Indexe
If idxSearch.Name = fieldname The
MsgBox "Deleting " & idxSearch.Nam
sql = "DROP INDEX " & fieldname & " ON " & tblName & ";
currentDB.Execute sq
' Also tried it with the delete method
' currentDB.TableDefs(tblName).Indexes.Delete fieldnam
End I
Nex
dropcolumn
' Delete the old field
sql = "ALTER TABLE [" & tblName & "] DROP COLUMN [
sql = sql & fieldname & "]
qdf.sql = sq
qdf.Execut
' Rename the temporary field to the old field's name
db.TableDefs("[" & tblName & "]").Fields("AlterTempField").Name = fieldnam
When the "ALTER TABLE DROP COLUMN" sql statement executes, I get
Run-time error '3280'
Can't delete a field that is part of an index or is needed by the system
Any ideas? Thanks.