J
Jonathan Wood
Greetings,
I'm trying to add an indexed field to a table using VBA.
After considerable searching, I came up with the following code.
Unfortunately, I get an error when I attempt to add the index to the Indexes
collection: Run-time error '3409': Invalid field definition 'ShipCustomerID'
in definition of index or relationship.
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim idx As DAO.Index
Dim fld As DAO.Field
Set db = CurrentDb
Set td = db.TableDefs("TempTable")
Set idx = td.CreateIndex("ShipCustomerID_Index")
Set fld = idx.CreateField("ShipCustomerID", dbText, 10)
fld.Required = False
idx.Fields.Append fld
idx.Primary = False
idx.Unique = False
idx.Required = False
td.Indexes.Append idx <== Error happens here
I don't see what is wrong with the field definition. Any help appreciated.
Also, if anyone know, I want this to be a foreign key. In Access, I guess
that means I need to create a relationship. I found various code for this
but no examples that just do this alone. A small code snippet would be
fantastic if anyone was so inclined.
Thanks!
Jonathan
I'm trying to add an indexed field to a table using VBA.
After considerable searching, I came up with the following code.
Unfortunately, I get an error when I attempt to add the index to the Indexes
collection: Run-time error '3409': Invalid field definition 'ShipCustomerID'
in definition of index or relationship.
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim idx As DAO.Index
Dim fld As DAO.Field
Set db = CurrentDb
Set td = db.TableDefs("TempTable")
Set idx = td.CreateIndex("ShipCustomerID_Index")
Set fld = idx.CreateField("ShipCustomerID", dbText, 10)
fld.Required = False
idx.Fields.Append fld
idx.Primary = False
idx.Unique = False
idx.Required = False
td.Indexes.Append idx <== Error happens here
I don't see what is wrong with the field definition. Any help appreciated.
Also, if anyone know, I want this to be a foreign key. In Access, I guess
that means I need to create a relationship. I found various code for this
but no examples that just do this alone. A small code snippet would be
fantastic if anyone was so inclined.
Thanks!
Jonathan