From: aligahk06 on
Dear All,


Could it be possible to find out primary key in a table and then redine the
primary key .

Any help?

Rgds,
Aligahk0
From: Stefan Hoffmann on
hi,

On 06.04.2010 08:59, aligahk06 wrote:
> Could it be possible to find out primary key in a table and then redine the
> primary key .
Sure, open the table in design view, and locate the key symbole on the
left side of each field. Mark the new fields and press the key button.

To do it in VBA you need to inspect the Indexes collection of a TableDef
object, e.g.

Dim db As DAO.Database
Dim fd As DAO.Field
Dim ix As DAO.Index
Dim td As DAO.TableDef

Set db = CurrentDb
Set td = db.TableDefs.Item("Information")
For Each ix In td.Indexes
Debug.Print ix.Name;
If ix.Primary Then
Debug.Print ":";
For Each fd In ix.Fields
Debug.Print " "; fd.Name;
Next fd
End If
Debug.Print
Next ix
Set td = Nothing
Set db = Nothing

To redefine the primary key you need to remove this index from the
Indexes collection and add an new index with Primary = True.


mfG
--> stefan <--