Removing field programmatically

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)?
 
G

Guest

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top