Removing field programmatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to script removal of a field from a BE:

Dim FilePath as String
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim tblName As String
Dim fldName As String

FilePath = <Path to DB>
tblName = "Table1"
fldName = "Field1"
Set db = DBEngine.Workspaces(0).OpenDatabase(FilePath, True)
Set tdf = db.TableDefs(tblName)
tdf.Fields.Delete fldName

However, Table1.Field1 Indexed property is Yes (No duplicates), so it fails
on the last line. I have checked the Indexes collection and find none for
that field. How can I change that field to Indexed: "No" so that I can then
delete it (or force-delete it without that)?
 
Never mind. I looped through the indexes four or five times and saw the name
of the index that needed to be deleted before I finally realized it was the
one I needed:

CurrentDb.TableDefs(tblName).Indexes.Delete idxName (and of course, idxName
was the same as TableName)
 
Back
Top