
Moving primary key from one field to another
Quote:
> >> It's an Access2000 and VB6, how can I move primary key from one field
> >> and put it onto another. Target field is a newly created field with
> >> autonumber so it is OK to be a PK.
With both ADO and DAO, you should be able to do a DROP INDEX followed by a
CREATE INDEX.
With DAO, you can drop the old PK with
db.TableDefs("MyTable").Indexes.Delete "PrimaryKey"
and create a new one with
Dim ix As Index
Set ix = db.TableDefs("MyTable").CreateIndex("PrimaryKey")
With ix
.Primary = True
.Unique = True
.Required = True
.Fields.Append .CreateField("NewKeyField")
End With
db.TableDefs("MyTable").Indexes.Append ix
ADOX probably has equivalents.