View Full Version : Problem :alter primary key of table using vb code


kvsurajin
07-22-2004, 09:46 PM
I have a problem. I have created a table with primary keys as a combination of two fields in ms-access. I want to remove the primary keys of the table using vb code. The data of the existing table should not be lost. I have tried alter table command in sql, but it does not work as the constraint name is not known.

WayneRyan
07-22-2004, 10:45 PM
k,

I never programmatically try to make changes to database
design. And I know you'll back up first.

You know the field names that comprise the index, they
are "+Field1;+Field2" (substitute your real names).



Dim i As Long
Dim j As Long
Dim tdf As DAO.TableDef
Dim idx As DAO.Index
Set dbs = CurrentDb
For i = 0 To dbs.TableDefs.Count - 1
Set tdf = dbs.TableDefs(i)
For j = 0 To tdf.Indexes.Count - 1
Set idx = tdf.Indexes(j)
If idx.Fields = "+Field1;+Field2" Then
tdf.Indexes.Delete (idx.Name)
End If
Next j
Next i


Wayne